Sibbs Gambling Sibbs Gambling - 11 months ago 53
Python Question

How to equalize the scales of x-axis and y-axis in Python matplotlib?

I wish to draw lines on a SQUARE graph.

The scales of

should be the same.

e.g. x ranges from 0 to 10 and it is 10cm on the screen. y has to also range from 0 to 10 and has to be also 10 cm.

The SQUARE shape has to be maintained, even if I mess around with the window size.

Currently, my graph scales together with the window size.

How may I achieve this?


I tried the following, but it did not work.

plt.xlim(-3, 3)
plt.ylim(-3, 3)

Answer Source

You need to dig a bit deeper into the api to do this:

plt.xlim(-3, 3)
plt.ylim(-3, 3)
plt.gca().set_aspect('equal', adjustable='box')

doc for set_aspect