Deformed rectangles with a decreasing trend
I need to implement some shapes in the picture using python (matplotlib).
Does anyone have an idea how I could achieve this? I tried working with polygons to create these warped rectangles, for example:
import matplotlib.pyplot as plt plt.axes() points = [[x, y]] polygon = plt.Polygon(points) plt.show()
but it just shows the coordinate system and nothing else, when I type x, y indicates getting a warped rectangle.
Edit
I have now used @ImportanceOfBeingErnest answer but it throws an error
Does anyone have any idea where this is coming from?
source to share
Here is a way to add a polygon to matplotlib axes. The polygon is an instance matplotlib.patches.Polygon
and is added to the axes with ax.add_patch
.
Since matplotlib does not autoscale the axes to include patches, the axis limits must be set.
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()
source to share