["Sascha" <saschagl@gmx.de>] Re: Re: [Matplotlib-users] Saving a figure toStringIO or similar

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

["Sascha" <saschagl@gmx.de>] Re: Re: [Matplotlib-users] Saving a figure toStringIO or similar

John Hunter-8

Thanks Sascha,

The point of my reply was that others can benefit from what you've
learned.  Even if you feel like you are a newbie, trust me, others
will be glad to benefit from what you've learned.  So please send the
information to the list.  I've forwarded your response.

Thanks!
JDH



> Could you post a complete example so that others won't have to spend
> that extra time figuring out how to put all the pieces together?

I think that it took me a little bit longer because I am not a very
proficient (Python) programmer. Others would probably figure this out much
quicker based on Nicholas' example.

Anyway, here's the example:

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

from matplotlib.backends.backend_agg \
    import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
import Image

def getImageData(format):
    fig = Figure()
    canvas = FigureCanvas(fig)
    ax = fig.add_subplot(111)
    ax.plot([1,2,3])
    ax.set_title('hi mom')
    ax.grid(True)
    ax.set_xlabel('time')
    ax.set_ylabel('volts')
    canvas.draw()
    size = canvas.get_width_height()
    buf=canvas.tostring_rgb()
    im=PILImage.fromstring('RGB', size, buf, 'raw', 'RGB', 0, 1)
    imdata=StringIO()
    im.save(imdata, format)
    return imdata

getImageData('PNG')
-------------------------------------

Sascha,
who likes MPL and the people that work with it :)


Reply | Threaded
Open this post in threaded view
|

Re: Saving a figure toStringIO or similar

Sascha-4
> Thanks Sascha,
>
> The point of my reply was that others can benefit from what you've
> learned.  Even if you feel like you are a newbie, trust me, others
> will be glad to benefit from what you've learned.  So please send the
> information to the list.  I've forwarded your response.

It's been a pleasure. I actually intended to send my reply to the list and
did not look at who I was really sending it to. Sorry again.

Sascha



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users