如何在Python matplotlib中使x轴和y轴的比例相等? [英] How to equalize the scales of x-axis and y-axis in Python matplotlib?
本文介绍了如何在Python matplotlib中使x轴和y轴的比例相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在正方形图上画线.
I wish to draw lines on a square graph.
x-axis
和y-axis
的小数位数应该相同.
The scales of x-axis
and y-axis
should be the same.
例如x的范围是0到10,在屏幕上是10厘米. y的范围也必须为0到10,并且也必须为10厘米.
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.
我该如何实现?
更新:
我尝试了以下操作,但是没有用.
I tried the following, but it did not work.
plt.xlim(-3, 3)
plt.ylim(-3, 3)
plt.axis('equal')
推荐答案
您需要对api进行更深入的研究:
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()
这篇关于如何在Python matplotlib中使x轴和y轴的比例相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文