0

This thread: Changing the "tick frequency" on x or y axis in matplotlib? answers how to set the tick spacing to a particular value. I do not want to specify what this spacing should be, but I would like the same spacing to be used on both axis without manually telling matplotlib what these ticks should be.

What I am doing now:

Data:

x = np.linspace(0,5,100)
y = np.sin(x)+np.random.normal(size = len(x))*0.1

Plot:

plt.figure(figsize=(10,10))
plt.plot(x,y)

plt.xticks(np.arange(min(x), max(x)+1, 1.0)); # I don't want to be doing this
plt.yticks(np.arange(min(y), max(y)+1, 1.0)); # I don't want to be doing this

plt.gca().set_aspect('equal')

enter image description here

This solution is rather inconvinient, because it requires me to manually set the spacing.

How can I tell matplotlib to select equal tick spacing for both axes?

zabop
  • 5,493
  • 3
  • 23
  • 56
  • 1
    You could use [`MultipleLocator`](https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.MultipleLocator)s with the same `base` for both axes but it's not automatic as you need to manually set the `base` and of course it doesn't work well when heavily zooming in or out. – Stef Nov 25 '21 at 11:47

0 Answers0