Please post the entire traceback so that we can know the context of the
error message. Also, exactly which versions of matplotlib and python are
you using?

Ben Root

On Sat, Nov 1, 2014 at 7:37 AM, Julien Hillairet <julien.hillai...@gmail.com
> wrote:

> Dear all,
>
> I'm trying to write a html page content in which a png figure is generated
> by matplotlib, with Python3.
>
> However, the following piece of code does not work with matplotlib/Python3
> (while it should work with Python2). The error is the following on
>
> TypeError: string argument expected, got 'bytes'
>
> when on fig.savefig(sio, format="png")
>
>
> Could someone explain me how to do it ?
>
> Best regards,
>
> Julien
>
> --------------------------------------------
>
> import matplotlib.pyplot as plt
>
>
> from io import StringIO
>
>  fig = plt.figure()
>
> ax = fig.add_subplot(111)
>
> ax.plot([1,2,3])
>
>
> sio = StringIO()
>
>
> fig.savefig(sio, format="png")
>
>
> html = """<html><body>
>
> ...a bunch of text and html here...
>
> <img src="data:image/png;base64,%s"/>
>
> ...more text and html...
>
> </body></html>""" % sio.getvalue().strip()
>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to