grover
grover

Reputation: 977

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?

Upvotes: 5

Views: 4763

Answers (2)

Brandon Schabell
Brandon Schabell

Reputation: 1925

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'

Upvotes: 4

Alex Alifimoff
Alex Alifimoff

Reputation: 1849

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.

Upvotes: -4

Related Questions