Embed logo in plot at actual size

Hi,

I'd like to know if it's possible to do something like this in matplotlib:

I want to create a 2D plot with legend, output as PNG. I also want to
embed a logo in it, in the top right corner of the plotting area. If
the original logo image is a 40px by 40px PNG, I want it to appear at
that size exactly as it is in the original logo.

Even if I can't do this directly, I might be able to fudge it if
matplotlib tells me the exact (pixel) dimensions of the plot area —
then I could scale and offset the secondary axes, convert the logo PNG
to RGB values and plot that (or use Python to invoke an imagemagick
subprocess and pass it those numbers... anything, really).

Is it possible to get this info from matplotlib, or is there a better
way to do this?

Cheers,
Jason

See

  http://matplotlib.sourceforge.net/examples/api/watermark_image.html

for an example of embedding a watermark image in mpl.

To compute figure size, multiply the DPI setting by the figure
dimensions in inches:

dpi = 100 # dpi, whatever value you want
width, height = 6,4 # in inches, whatever values you want

fig = plt.figure(figsize=(width, height), dpi=dpi)
pixelw = dpi * width # pixel width of figure
pixelh = dpi * height # pixel height of figure

# now watermark you figure as in the example linked above, passing the
pixel coords of the lower left corner of the image to figimage

# this last piece is important: pass dpi to savefig too since mpl
supports different dpi for display and hardcopy

fig.savefig(myfile, dpi=dpi)

JDH

···

On Mon, Nov 16, 2009 at 4:12 AM, Jason Heeris <jason.heeris@...287...> wrote:

Hi,

I'd like to know if it's possible to do something like this in matplotlib:

I want to create a 2D plot with legend, output as PNG. I also want to
embed a logo in it, in the top right corner of the plotting area. If
the original logo image is a 40px by 40px PNG, I want it to appear at
that size exactly as it is in the original logo.

Even if I can't do this directly, I might be able to fudge it if
matplotlib tells me the exact (pixel) dimensions of the plot area —
then I could scale and offset the secondary axes, convert the logo PNG
to RGB values and plot that (or use Python to invoke an imagemagick
subprocess and pass it those numbers... anything, really).

Is it possible to get this info from matplotlib, or is there a better
way to do this?

John Hunter wrote:

See

  http://matplotlib.sourceforge.net/examples/api/watermark_image.html

for an example of embedding a watermark image in mpl.

To compute figure size, multiply the DPI setting by the figure
dimensions in inches:

This is a good place to start, so thanks :slight_smile: I'll keep poking around, but
do you know if it's possible to get the location of the plot area
*within* the image? That is, the coordinates of the area within the axes?

Cheers,
Jason