matplotlib.pyplot,保留绘图的长宽比 [英] matplotlib.pyplot, preserve aspect ratio of the plot

查看:1128
本文介绍了matplotlib.pyplot,保留绘图的长宽比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个多边形坐标,例如多边形= [(x1,y1),(x2,y2),...],下面的代码将显示该多边形:

Assuming we have a polygon coordinates as polygon = [(x1, y1), (x2, y2), ...], the following code displays the polygon:

import matplotlib.pyplot as plt
plt.fill(*zip(*polygon))
plt.show()

默认情况下,它会尝试调整纵横比,以使多边形(或其他任何图表)适合窗口内部,并自动更改它,以便即使在调整大小后也适合.在许多情况下,这很有用,除非您试图通过视觉估算图像是否失真.如何将长宽比固定为严格的1:1?

By default it is trying to adjust the aspect ratio so that the polygon (or whatever other diagram) fits inside the window, and automatically changing it so that it fits even after resizing. Which is great in many cases, except when you are trying to estimate visually if the image is distorted. How to fix the aspect ratio to be strictly 1:1?

(不确定长宽比"是否在这里是正确的术语,因此,如果不是-我需要X和Y轴都具有1:1比例,以便X和Y上都为(0,1)占用完全相同的屏幕空间.无论我如何调整窗口大小,我都必须将其保持为1:1.)

(Not sure if "aspect ratio" is the right term here, so in case it is not - I need both X and Y axes to have 1:1 scale, so that (0, 1) on both X and Y takes an exact same amount of screen space. And I need to keep it 1:1 no matter how I resize the window.)

推荐答案

使用是否有帮助:

plt.axis('equal')

这篇关于matplotlib.pyplot,保留绘图的长宽比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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