chevron_left
Axes Cookbook
check_circle
Mark as learned thumb_up
0
thumb_down
0
chat_bubble_outline
0
auto_stories new
settings
Drawing the axis line in Matplotlib
Matplotlib
chevron_rightCookbooks
chevron_rightAxes Cookbook
schedule Sep 6, 2022
Last updated local_offer Python●Matplotlib
Tags tocTable of Contents
expand_more Check out the interactive map of data science
To draw the axis line in Matplotlib, use the axhline(~)
and axvline(~)
methods:
plt.axhline(0) #x-axis lineplt.axvline(0) #y-axis lineplt.xlim(-5,5)plt.ylim(-5,5)plt.show()
The output is as follows:

Changing transparency
Usually, you want the axis lines to be slightly transparent, so here's some code for that:
plt.axhline(0, color="blue", alpha=0.3)plt.axvline(0, color="blue", alpha=0.3)plt.xlim(-5,5)plt.ylim(-5,5)plt.show()
The output is as follows:

Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
thumb_up
thumb_down
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!