Dear Matplotlibers, I'm trying to insert a logo image (from PNG) in the top left corner of my axes. I'm doing this by reading the logo using read_png() and inserting it as an OffsetImage in an AnnotationBox. When saving the figure as PNG everything is based on pixel sizes and I know how to scale the OffsetImage such that I end up with the desired logo size (based on the figure and logo sizes in pixels). Saving as PDF, however, does not depend on pixel sizes, and I end up with a 'different' size of the logo.
Could someone please tell me what determines the size of the OffsetImage when saving as PDF? And maybe even better, how to achieve scaling that results in the same size logo as in the PNG output? I have attached: 1a) A small test.py script that produces PNG and PDF output showing the different logo sizes. Uncommenting the zoom_factor line shows how to scale the logo independent of the figure size/dpi settings. 1b) A dummy PNG logo file. 2) Two example output files (PNG and PDF) showing the output of test.py. Any hints would be much appreciated! Best regards, Jeroen
<<inline: dummy.png>>
test.pdf
Description: Adobe PDF document
<<inline: test.png>>
#!/usr/bin/env python import matplotlib from matplotlib import pyplot as plt import numpy as np from matplotlib._png import read_png from matplotlib.offsetbox import OffsetImage from matplotlib.offsetbox import AnnotationBbox if __name__ == "__main__": matplotlib.rcParams["figure.figsize"] = (8., 6.) matplotlib.rcParams["figure.dpi"] = 200 matplotlib.rcParams["savefig.dpi"] = matplotlib.rcParams["figure.dpi"] fig = plt.figure() ax = fig.add_subplot(111) logo_data = read_png("dummy.png") fig_dpi = ax.get_figure().dpi fig_size = ax.get_figure().get_size_inches() zoom_factor = 1. # zoom_factor = .1 * fig_dpi * fig_size[0] / np.shape(logo_data)[0] logo_box = OffsetImage(logo_data, zoom=zoom_factor) ann_box = AnnotationBbox(logo_box, [0., 1.], xybox=(2., -3.), xycoords="axes fraction", boxcoords="offset points", box_alignment=(0., 1.), pad=0., frameon=False) ax.add_artist(ann_box) fig.savefig("test.png") fig.savefig("test.pdf") plt.close()
------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users