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

I want to draw lines on a SQUARE graph.

The x-axis and y-axis must be the same.

eg. x is between 0 and 10 and 10 cm on the screen. y should also vary from 0 to 10 and should also be 10 cm.

The SQUARE form must be supported even if I am dealing with window size.

My graph is currently being scaled along with the window size.

How can i achieve this?

UPDATE:

I tried the following, but that did not work.

 plt.xlim(-3, 3) plt.ylim(-3, 3) plt.axis('equal') 
+90
python matplotlib
Aug 01 '13 at 9:58 am
source share
4 answers

You need to dig a bit into the API to do this:

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

document for set_aspect

+133
Aug 01 '13 at
source share
 plt.axis('scaled') 

works well for me

+53
Dec 17 '16 at 16:15
source share

Try something like:

 import pylab as p p.plot(x,y) p.axis('equal') p.show() 
+17
Aug 01 '13 at
source share

See the documentation at plt.axis() . It:

 plt.axis('equal') 

does not work, because it changes the boundaries of the axis so that the circles look round. What you want is:

 plt.axis('square') 

This creates a square graph with equal axes.

+2
Sep 01 '19 at 18:55
source share



All Articles