Skip to content

savefig to StringIO crashes #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2012
Merged

savefig to StringIO crashes #678

merged 2 commits into from
Jan 18, 2012

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Jan 17, 2012

Example code:

import pylab, StringIO

out = StringIO.StringIO()
pylab.plot([1, 2, 3])
pylab.savefig(out, format = "svg")

Crashes here:
https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_svg.py#L1067
AttributeError: readable (apparently, it expects an io.StringIO file object)

... but using io.StringIO crashes as well, with an unicode issue:
TypeError: string argument expected, got 'str'

The only workaround I have found so far consists in subclassing StringIO:

class MyStringIO(StringIO):
    def readable(self):
        return True

    def writable(self):
        return True

    def seekable(self):
        return True

@mdboom
Copy link
Member

mdboom commented Jan 17, 2012

I have attached a pull request that I believe addresses this. I wasn't aware that the io module and the cStringIO module are effectively incompatible. I've reverted to the old way of doing things for Python 2.x

mdboom added a commit that referenced this pull request Jan 18, 2012
savefig to StringIO crashes
@mdboom mdboom merged commit bbe02dd into matplotlib:master Jan 18, 2012
@mdboom mdboom deleted the svg/stringio branch March 3, 2015 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants