Matplotlib - Das Bild nicht zum Drehen von Polygon (Python) ausschlägt,
Posted: 08 Feb 2025, 17:58
Bei meinem Projekt möchte ich mit Matplotlib in gedrehte Rechteck -Polygone in gedrehte Rechteck -Polygone einklemmen. > Das Bild passt also nur zum Polygon-Rechteck kurz.
Aber für 90 Grad erhalte ich den folgenden Clip:
< /p>
und für 45 Grad empfange ich Folgendes: < /p>
Dies ist das Originalbild. = "https://i.static.net/epuhgazp.png"/>
Code: Select all
poly = [(0, 0), (5, 0), (5, 10), (0, 10)]
rotate_angle = 90
target_polygon = np.array([rotate_point(point, rotate_angle) for point in poly])
pv_module_img = plt.imread("..\\module_img.png")
pv_module_img_uint8 = (pv_module_img * 255).astype(np.uint8)
pv_module_img_reshaped = np.squeeze(pv_module_img_uint8)
rotated = Image.fromarray(pv_module_img_reshaped).rotate(rotate_angle)
fig, ax = plt.subplots(figsize=(8, 6))
extent = set_pv_modules_envelope(target_polygon)
patch = mp.Polygon(target_polygon, closed=True)
ax.add_patch(patch)
ax.imshow(
rotated,
extent=extent,
clip_path=patch,
clip_on=True,
zorder=3
)
plt.axis("scaled")
plt.axis("off")
plt.show()
< /p>
und für 45 Grad empfange ich Folgendes: < /p>
Dies ist das Originalbild. = "https://i.static.net/epuhgazp.png"/>