From: Jake E. <jak...@on...> - 2007-06-11 03:10:18
|
The python imaging library is pretty good for this kind of thing. =20 http://www.pythonware.com/library/pil/handbook/ =20 Here's an (untested) example. Hope it helps. =20 Jake =20 =20 #!/usr/bin/env python =20 from pylab import scatter, save import Image =20 #get the background image, and find out how big it is im_bg =3D Image.open("background.png") bg_width, bg_height =3D im.size =20 #make a white canvas on which to paste the background image and the scatter plot #this will allow you to, say, have the x- and y-axis values fall outside of the background image's limits im_canvas =3D Image.new("RGBA", (bg_width+60, bg_height+60), (255, 255, 255, 0)) =20 #create the scatter plot from x and y data with matplotlib scatter(x, y, s=3Dsizes, alpha=3D0.75) =20 #save the scatter plot, and then retrieve it for use in PIL, convert to RGBA so that alpha levels will work #there is probably a better way to do this with gcf() or gci()... savefig("scatter_plot.png") im_scatter =3D Image.open("scatter_plot.png").convert("RGBA") =20 #resize the scatter image to make it fit nice im_scatter.resize((bg_width+10, bg_height+10)) =20 #bring all of the images together by pasting them onto the white canvas, use the overlayed image as the mask (third element) im_canvas.paste(im_bg, (30, 30), im_bg) #play around with the paste locations (30, 30) im_canvas.paste(im_scatter, (10, 30), im_scatter) #these won't be perfect the first time (10, 30) =20 #save it im_canvas.save("combo_image.png") =20 =20 =20 =20 ________________________________ From: __ [mailto:red...@gm...]=20 Sent: Sunday, June 10, 2007 5:22 PM To: mat...@li... Subject: [Matplotlib-users] Simple scatter plot over an image Hello,=20 I'm trying to plot a simple list of x/y coords over an image (.png). I can show the image, or plot the data, but cannot find a way to layer one over the other. I would greatly appreciate someone pointing me in the right direction. Thanks.=20 |