Exemple de comment insérer une image extérieure dans une figure matplotlib en utilisant annotation. L'image utilisée ici est Lenna.png

from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBboximport matplotlib.pyplot as pltimport matplotlib.image as mpimgfig, ax = plt.subplots()ax.set_xlim(0, 1)ax.set_ylim(0, 1)arr_lena = mpimg.imread('Lenna.png')imagebox = OffsetImage(arr_lena, zoom=0.2)ab = AnnotationBbox(imagebox, (0.4, 0.6))ax.add_artist(ab)plt.grid()plt.draw()plt.savefig('add_picture_matplotlib_figure.png',bbox_inches='tight')plt.show()
Références
| Liens | Site |
|---|---|
| pylab_examples example code: demo_annotation_box.py | matplotlib doc |
| Combine picture and plot with Python Matplotlib | stackoverflow |
| how to insert a small image on the corner of a plot with matplotlib? | stackoverflow |
| Annotating Axes | matplotlib doc |
