How to equalize the scales of x-axis and y-axis


I wish to draw lines on a square graph.

The scales of x-axis and y-axis 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)
Asked By: Sibbs Gambling



Try something like:

import pylab as p
Answered By: Dman2

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

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

doc for set_aspect

Answered By: tacaswell

works well for me.

Answered By: myx

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


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


This creates a square plot with equal axes.

Answered By: Adam Stewart

you can stretch the plot to square using this :

fig = plt.figure(figsize=(1, 1))
Answered By: rzb
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.