5

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 2

4

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'
2
  • 1
    the 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
-4

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.

1
  • 2
    This 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.
    – grover
    Commented Jan 22, 2016 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.