Skip to content Skip to sidebar Skip to footer

Deformed Rectangulars With Decreasing Trend

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 defo

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

enter image description here

Post a Comment for "Deformed Rectangulars With Decreasing Trend"