Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

How do you make X and Y axis scales the same in Python?

If we use "equal" as an aspect ratio in the function, we get a plot with the same scaling from data points to plot units for X-axis and Y-axis. It sets both X-axis and Y-axis to have the same range. Then ax. set_aspect('equal') sets both axes to be equal.

How do I scale axes in Matplotlib?

Import matplotlib. To set x-axis scale to log, use xscale() function and pass log to it. To plot the graph, use plot() function. To set the limits of the x-axis, use xlim() function and pass max and min value to it. To set the limits of the y-axis, use ylim() function and pass top and bottom value to it.

What are the two ways to adjust axis limits of the plot using Matplotlib?

Adjust axis limits: To set the limits of x and y axes, we use the commands plt. xlim() and plt. ylim().


You need to dig a bit deeper 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()

doc for set_aspect


plt.axis('scaled')

works well for me.


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.


Try something like:

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