I want to insert a scaled image on a figure and align it to right figure border. The following works fine in the interactive windows and when saving as png, but when saving as a pdf the image is too to the left. How can i get the correct behavior for both cases? This happens also if the savefig and figure settings are identical.
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage
import numpy as np
fig = plt.figure(dpi=100)
image = np.ones((200, 200))
ob = OffsetImage(image, zoom=0.5)
rend = fig.canvas.get_renderer()
w, h, x, d = ob.get_extent(rend)
fig.images.append(ob)
ob.set_offset((fig.bbox.xmax-w, 0))
plt.show()
fig.savefig("bla.pdf", dpi=100)