如何在matplotlib中均衡x轴和y轴的比例? [英] How to equalize the scales of x-axis and y-axis in matplotlib?

查看:66
本文介绍了如何在matplotlib中均衡x轴和y轴的比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在方图上画线.

x-axisy-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()

set_aspect 文档

这篇关于如何在matplotlib中均衡x轴和y轴的比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆