Is there a way to make the direction of the tick marks on the bottom of the xaxis point outward, but the top ones point inward, using matplotlib?
2 Answers
Yes! You can use the set_tick_params() method to do this. Here's an example for setting up a histogram to work as you described:
hist.xaxis.set_ticks_position('both') # Adding ticks to both top and bottom
hist.xaxis.set_tick_params(direction='in', which='top') # The bottom will maintain the default of 'out'
-
1the second line seems to no longer work:
ValueError: 'top' is not a valid value for which; supported values are 'major', 'minor', 'both'
Commented Apr 19, 2022 at 17:52 -
Also, is there a way to set this behavior by default via
rcParams
? Commented Apr 19, 2022 at 18:35
You can change the ascending/descending order of tick marks by passing in limits for the x and y-axes that decrease.
I.E. to make the x-axis go from 10 to 0, instead of 0 to 10 and the y-axis to go from 10 to -10, you can do:
plt.xlim(10, 0)
plt.ylim(10, -10)
Here is an example from matplotlib demonstrating this functionality on a simple case.
-
2This has to do with the labels on the tick marks. I am asking about the tick mark lines on the graph, and whether they point in towards the graph or outwards.– groverCommented Jan 22, 2016 at 20:29