Ich mache Illustrationen für mein Papier in Python mit matplotlib
Bibliothek. In dieser Illustration habe ich viele Linien, Polygone, Kreise etc. Aber dann möchte ich auch ein .png
Bild von außen einfügen.Einfügen/Anpassen von Png in Plot [Matplotlib]
Hier ist, was ich versuche, so weit zu tun:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon
fig, ax = plt.subplots()
plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
ax.axis('off')
# drawing circle
ax.add_patch(
plt.Circle((0, 0), 0.5, color = 'black')
)
# drawing polygon
ax.add_patch(
Polygon(
[[0,0], [20, 15], [20, 40]],
closed=True, fill=False, lw=1)
)
# importing image
im = plt.imread("frame.png")
# defining image position/size
rect = 0.5, 0.4, 0.4, 0.4 # What should these values be?
newax = fig.add_axes(rect, anchor='NE', zorder=1)
newax.imshow(im)
newax.axis('off')
ax.set_aspect(1)
ax.set_xlim(0, 60)
ax.set_ylim(0, 40)
plt.show()
Die Frage ist also, wie kann ich feststellen, die Werte für rect = 0.5, 0.4, 0.4, 0.4
? Zum Beispiel möchte ich, dass die untere linke Ecke meines .png
an dem Punkt [20, 15]
liegt und ich möchte, dass seine Höhe 25
ist.
Dies ist das resultierende Bild:
Aber ich will diese Dummy-Rahmen meiner Polygonpunkte eingestellt werden, wie dies (dieses in Photoshop angepasst ist):
PS Hier ist die link mit der frame.png
zu experimentieren.
Danke, das für mich gearbeitet. Hätte nicht geglaubt, dass die Antwort so einfach wäre. Entschuldigung, wenn die Frage zu dumm war. –