The Python Oracle

How do I equalize the scales of the x-axis and y-axis?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Civilization

--

Chapters
00:00 Question
00:29 Accepted answer (Score 282)
00:47 Answer 2 (Score 95)
00:59 Answer 3 (Score 64)
01:24 Answer 4 (Score 22)
01:37 Thank you

--

Full question
https://stackoverflow.com/questions/1799...

Accepted answer links:
[Axes.set_aspect]: https://matplotlib.org/stable/api/_as_ge...

Answer 3 links:
[the documentation]: https://matplotlib.org/api/_as_gen/matpl...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #matplotlib

#avk47



ACCEPTED ANSWER

Score 315


Use Axes.set_aspect in the following manner:

from matplotlib import pyplot as plt
plt.plot(range(5))
plt.xlim(-3, 3)
plt.ylim(-3, 3)
ax = plt.gca()
ax.set_aspect('equal', adjustable='box')
plt.draw()



ANSWER 2

Score 105


plt.axis('scaled')

works well for me.




ANSWER 3

Score 74


See the documentation on plt.axis(). This:

plt.axis('equal')

doesn't work because it changes the limits of the axis to make circles appear circular. What you want is:

plt.axis('square')

This creates a square plot with equal axes.




ANSWER 4

Score 25


Try something like:

import pylab as p
p.plot(x,y)
p.axis('equal')
p.show()