From: Wayne W. <sie...@sb...> - 2010-01-15 23:15:31
|
I've used MPL a bit, and am wondering if there's a facility for sending graphic images to a printer, or putting them in some format like png? I don't necessarily want the graphics to appear in a window, but would like to print them directly once they are ready. Can one put in a page feed, so that images don't all fall on the same page or cut across pages? Is there any image processing operation available to do simple operations like dark subtract or stack different images on one other to produce composites of several images? Maybe Python has such a facility that's already available as a library? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "I was thinking about how people seem to read the Bible a whole lot more as they get older; then it dawned on me . . they're cramming for their final exam." -- George Carlin Web Page: <www.speckledwithstars.net/> |
From: Michael D. <md...@st...> - 2010-01-19 14:01:13
|
Wayne Watson wrote: > I've used MPL a bit, and am wondering if there's a facility for sending > graphic images to a printer, or putting them in some format like png? > I don't necessarily want the graphics to appear in a window, but would > like to print them directly once they are ready. Can one put in a page > feed, so that images don't all fall on the same page or cut across pages? > You can use one of the non-GUI backends to generate plots in a number of formats, including PNG, PDF, PS and SVG. See this: http://matplotlib.sourceforge.net/faq/installing_faq.html#backends The PDF backend is the only one I'm aware of that supports multiple pages. This is the docstring for PdfPages: A multi-page PDF file. Use like this:: # Initialize: pp = PdfPages('foo.pdf') # As many times as you like, create a figure fig, then either: fig.savefig(pp, format='pdf') # note the format argument! # or: pp.savefig(fig) # Once you are done, remember to close the object: pp.close() (In reality PdfPages is a thin wrapper around PdfFile, in order to avoid confusion when using savefig and forgetting the format argument.) > Is there any image processing operation available to do simple > operations like dark subtract or stack different images on one other to > produce composites of several images? Maybe Python has such a facility > that's already available as a library? > > Matplotlib doesn't have a very strong set of these things built-in (though some things are possible with the image support in the image module). You can also get an rgb buffer of the figure (when using the Agg backend), eg. (where 'fig' is the figure object): fig.canvas.get_renderer().tostring_rgb() This is a string of 24-bit rgb triples, which can be converted to the Numpy array for arithmetical processing, or converted to a Python Imaging Library Image object. Mike -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
From: Wayne W. <sie...@sb...> - 2010-01-19 15:21:32
|
Thanks. I'll keep this in mind when I get to the point when I'm ready to consider it as part of a program I'm writing. Someone in Image-SIG sent me a module he wrote that might be helpful too. Michael Droettboom wrote: > Wayne Watson wrote: >> I've used MPL a bit, and am wondering if there's a facility for >> sending graphic images to a printer, or putting them in some format >> like png? I don't necessarily want the graphics to appear in a >> window, but would like to print them directly once they are ready. >> Can one put in a page feed, so that images don't all fall on the same >> page or cut across pages? >> > You can use one of the non-GUI backends to generate plots in a number > of formats, including PNG, PDF, PS and SVG. See this: > > http://matplotlib.sourceforge.net/faq/installing_faq.html#backends > > The PDF backend is the only one I'm aware of that supports multiple > pages. This is the docstring for PdfPages: > > A multi-page PDF file. > > Use like this:: > > # Initialize: > pp = PdfPages('foo.pdf') > > # As many times as you like, create a figure fig, then either: > fig.savefig(pp, format='pdf') # note the format argument! > # or: > pp.savefig(fig) > > # Once you are done, remember to close the object: > pp.close() > > (In reality PdfPages is a thin wrapper around PdfFile, in order to > avoid confusion when using savefig and forgetting the format > argument.) > >> Is there any image processing operation available to do simple >> operations like dark subtract or stack different images on one other >> to produce composites of several images? Maybe Python has such a >> facility that's already available as a library? >> >> > Matplotlib doesn't have a very strong set of these things built-in > (though some things are possible with the image support in the image > module). You can also get an rgb buffer of the figure (when using the > Agg backend), eg. (where 'fig' is the figure object): > > fig.canvas.get_renderer().tostring_rgb() > > This is a string of 24-bit rgb triples, which can be converted to the > Numpy array for arithmetical processing, or converted to a Python > Imaging Library Image object. > > Mike > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet "I was thinking about how people seem to read the Bible a whole lot more as they get older; then it dawned on me . . they're cramming for their final exam." -- George Carlin Web Page: <www.speckledwithstars.net/> |
From: Christopher B. <Chr...@no...> - 2010-01-19 17:26:58
|
> Wayne Watson wrote: >> I've used MPL a bit, and am wondering if there's a facility for sending >> graphic images to a printer, or putting them in some format like png? you've already gotten an answer to the png part, but as for printing directly: I suspect you could make a pdf and send that to the printer with a system call, though it would be different on each system, and I don't know how any of those work any more (you used to be able to do "print filename" on Windows (or DOS, anyway!), and, of course, on *nix systems, "lpr filename" used to work. Another option is to use a GUI back end, but never bring up a window. You can use wxPython this way -- you need to create a wx.App(), and you may need to create a wx.Frame to put the MPL plot in (or you may not), but you don't have to Show() it. You an then call the wx printing code to print. I imagine it's similar for QT and GTK and TK. Note that for wx at least, you do need access to a Windowing system, even if you aren't displaying anything. HTH, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |