surrutiaquir
surrutiaquir

Reputation: 103

Same ticks in log-plot

I'm generating a logplot using the following lines:

# Set log-los scale and axes
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$y$')
ax.set_aspect('equal')
ax.set_xlim([1e-7, 1e0])
ax.set_ylim([1e-7, 1e0])

but the result is not what I expected:

How can I make the x-axis look like the y-axis in terms of ticks? Thanks

Upvotes: 1

Views: 105

Answers (1)

tdy
tdy

Reputation: 41327

While it's technically true that ax.set_adjustable('datalim') brings back the minor ticks, that's only because it negates the equal axes set in this line:

...
ax.set_aspect('equal')
...

The root cause: set_aspect('equal') shrinks the x axis to the point that matplotlib decides to auto-remove the minor ticks.


To have both an equal aspect ratio and minor x ticks, use the LogLocator from the ticker module:

from matplotlib.ticker import LogLocator

ax.xaxis.set_major_locator(LogLocator(numticks=10))
ax.xaxis.set_minor_locator(LogLocator(numticks=10, subs=np.arange(0.1, 1, 0.1)))

Upvotes: 3

Related Questions