Rotating an AnnotationBbox image inside a python plot

Viewed 102

I am trying dearly to rotate an image I added into a python plot using OffsetImage and AnnotationBbox from matplotlib. It is very similar to this precise and concise example from https://moonbooks.org/Articles/How-to-insert-an-image-a-picture-or-a-photo-in-a-matplotlib-figure/ The example code found on that site is:

from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage, AnnotationBbox

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

fig, 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()

I would simply like to rotate the image plotted here by a certain angle.

Thank you!

Example of what I would like

0 Answers
Related