Home > Software engineering >  Same ticks in log-plot
Same ticks in log-plot

Time:09-25

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

CodePudding user response:

Add ax.set_adjustable("datalim"):

import matplotlib.pyplot as plt
  
fig, ax = plt.subplots()
  
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])

ax.set_adjustable("datalim")

ax.plot([0.001, 0.003, 0.0010], [0.001, 0.009, 0.0010], "o-",  color ="green")
  
fig.suptitle('matplotlib.axes.Axes.set_yscale()\
 function Example\n', fontweight ="bold")
plt.show()

enter image description here

CodePudding user response:

The minor x ticks disappear because ax.set_aspect('equal') shrinks the width. ax.set_adjustable('datalim') does bring back the minor x ticks, but removes the equal axes.

To keep the minor x ticks with an equal aspect ratio, use the

  • Related