Printing gif images to file with matplotlib

Hi,
I have recently come across Matplotlib and I am very impressed with its capabilities. I am new to both Matplotlib and Python, although I have several years experience with C++ and a few other languages *(including modelling with MatLab).
I have successfully embedded Python in a C++ application, and can run python scripts from my C++ application. However, I have found displaying graphs in a GUI fraught with (insurmountable?) problems and I have decided to NOT use a GUI at all, but rather, to save plots as image, to file (e.g. png, gif or jpeg).
Can anyone give me a simple example script that shows how I may use savefig(), to save a plot as an image (any of the above formats), to file?

Thanks

···

Connect to the next generation of MSN Messenger Get it now!

You can just pass a path to savefig, e.g.:

  savefig("/home/me/test.png")

(The format is automatically determined from the extension). If you want to know which formats are supported by which backends, you can have a look at FILETYPES in the source tree here:

http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/FILETYPES?view=markup

Many of the examples for matplotlib have savefig, but the line is usually commented out. Just remove the '#' and you have lots of examples.

Cheers,
Mike

Takashi Yamamoto wrote:

···

Hi,

I have recently come across Matplotlib and I am very impressed with its capabilities. I am new to both Matplotlib and Python, although I have several years experience with C++ and a few other languages *(including modelling with MatLab).

I have successfully embedded Python in a C++ application, and can run python scripts from my C++ application. However, I have found displaying graphs in a GUI fraught with (insurmountable?) problems and I have decided to NOT use a GUI at all, but rather, to save plots as image, to file (e.g. png, gif or jpeg).

Can anyone give me a simple example script that shows how I may use *savefig*(), to save a plot as an image (any of the above formats), to file?

Thanks

------------------------------------------------------------------------
Connect to the next generation of MSN Messenger Get it now! <http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline>

------------------------------------------------------------------------

-------------------------------------------------------------------------
SF.Net email is sponsored by: Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA