Skip to content Skip to sidebar Skip to footer

Direction Of Tick Marks In Matplotlib

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?

Solution 1:

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'

Solution 2:

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.

Post a Comment for "Direction Of Tick Marks In Matplotlib"