deformed rectangulars with decreasing trend

 ̄綄美尐妖づ 提交于 2019-12-25 12:13:12

问题


i have to implement some figures like that on the Picture with python (matplotlib).

Has anyone an idea how i could achieve this? I tried to work with polygons to create these deformed rectangulars, for example like this:

import matplotlib.pyplot as plt

plt.axes()

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

plt.show()

but it just shows a coordinate system and nothing else when I type in the x,y points to get a deformed rectangular.

Edit

I now used the answer by @ImportanceOfBeingErnest, but throws an error

Does anyone have an idea where this comes from?


回答1:


Here is a way to add a polygon to a matplotlib axes. The polygon is an instance of matplotlib.patches.Polygon and it is appended to the axes using ax.add_patch.

Since matplotlib does not autoscale the axes to include patches, it is necessary to set the axis limits.

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



来源:https://stackoverflow.com/questions/42875357/deformed-rectangulars-with-decreasing-trend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!