Is there a way to have top ticks in and bottom tick out in matplotlib plots? Sometimes I have data hiding ticks and I would like to set ticks out only for the side that is affected.
The following code will affect both top and bottom or both right and left.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot( 111 )
ax.plot( [0, 1, 3], 'o' )
ax.tick_params( direction = 'out' )
plt.show()
With the upgrade from #11859 for matplotlib>=3.1.0
we can now use a Secondary Axis via secondary_xaxis
and secondary_yaxis
to achieve independent tick directions:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot( 111 )
ax.plot( [0, 1, 3], 'o' )
ax.tick_params( direction = 'out' )
ax_r = ax.secondary_yaxis('right')
ax_t = ax.secondary_xaxis('top')
ax_r.tick_params(axis='y', direction='in')
ax_t.tick_params(axis='x', direction='inout')
which produces this figure:
You can have twin axes, then you can set the properties for each side separately:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([0, 1, 3], 'o')
axR = ax.twinx()
axT = ax.twiny()
ax.tick_params(direction = 'out')
axR.tick_params(direction = 'in')
ax.tick_params(direction = 'out')
axT.tick_params(direction = 'in')
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With