Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib - ticks direction for a plot in logarithmic scale

I would like to plot ticks markers inside of the layout. But since an update of Python, these markers are plotted outside... I try to add "ax.yaxis.set_tick_params(direction = 'in')" in my script. It works only for major values.

fig, ax = plt.subplots()
plt.loglog(testI[:],a[:],'b+',linewidth=2,label='a');

plt.loglog(testI[:],b[:],'y+',linewidth=2,label='b');

plt.xlim(6,45)
plt.ylim(10**(-7),19**(-1))

ax.yaxis.set_tick_params(direction = 'in')
ax.xaxis.set_tick_params(direction = 'in')

plt.show()

enter image description here

like image 851
user3601754 Avatar asked Sep 13 '25 23:09

user3601754


1 Answers

The set_tick_params method takes a keyword argument which that defaults to 'major'. You want to pass 'both' to also include the minor ticks.

Example:

from matplotlib import pyplot
(figure, axes) = pyplot.subplots()
axes.loglog([], [])
axes.set_xlim(1,100)
axes.set_ylim(1,100)
axes.xaxis.set_tick_params(direction='in', which='both')
axes.yaxis.set_tick_params(direction='in', which='both')
pyplot.show()

You could also use axes.tick_params in that example to configure both axes in one call.

like image 113
john-hen Avatar answered Sep 16 '25 13:09

john-hen