变形的矩形,呈下降趋势

时间:2017-03-18 14:04:57

标签: python forms matplotlib rectangles

我必须使用python(matplotlib)在Picture上实现一些类似的数字。

Picture

有谁知道我怎么能做到这一点?我尝试使用多边形来创建这些变形的矩形,例如:

import matplotlib.pyplot as plt

plt.axes()

points = [[x, y]]    
polygon = plt.Polygon(points)

plt.show()

但它只显示一个坐标系,当我输入x,y点以获得变形的矩形时,没有别的。

修改

我现在使用@ImportanceOfBeingErnest的答案,但是会抛出错误

Picture

有没有人知道这是从哪里来的?

1 个答案:

答案 0 :(得分:1)

这是一种向matplotlib轴添加多边形的方法。多边形是matplotlib.patches.Polygon的实例,它使用ax.add_patch附加到轴。

由于matplotlib不会自动调整轴以包含补丁,因此需要设置轴限制。

import matplotlib.pyplot as plt
import matplotlib.patches

x = [1,10,10,1,1]
y = [2,1,5,4,2]
points = list(zip(x,y))

polygon = matplotlib.patches.Polygon(points, facecolor="#aa0088")

fig, ax = plt.subplots()
ax.set_aspect("equal")
ax.add_patch(polygon)

ax.set_xlim(0,11)
ax.set_ylim(0,6)
plt.show()

enter image description here