Skip to content

Use io.BytesIO instead of io.StringIO in examples #6205

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
Mar 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/faq/howto_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,12 @@ or by saving to a file handle::
fig.savefig(sys.stdout)

Here is an example using `Pillow <http://python-imaging.github.io/>`_.
First, the figure is saved to a StringIO object which is then fed to
First, the figure is saved to a BytesIO object which is then fed to
Pillow for further processing::

import StringIO, Image
imgdata = StringIO.StringIO()
from io import BytesIO
from PIL import Image
imgdata = BytesIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0) # rewind the data
im = Image.open(imgdata)
Expand Down
6 changes: 3 additions & 3 deletions examples/misc/svg_filter_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
ax.set_xlim(0., 1.)
ax.set_ylim(0., 1.)

# save the figure as a string in the svg format.
from io import StringIO
f = StringIO()
# save the figure as a bytes string in the svg format.
from io import BytesIO
f = BytesIO()
plt.savefig(f, format="svg")


Expand Down
4 changes: 2 additions & 2 deletions examples/misc/svg_filter_pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@


# save
from io import StringIO
f = StringIO()
from io import BytesIO
f = BytesIO()
plt.savefig(f, format="svg")

import xml.etree.cElementTree as ET
Expand Down
4 changes: 2 additions & 2 deletions examples/user_interfaces/svg_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import numpy as np
import matplotlib.pyplot as plt
import xml.etree.ElementTree as ET
from io import StringIO
from io import BytesIO
import json

plt.rcParams['svg.embed_char_paths'] = 'none'
Expand Down Expand Up @@ -76,7 +76,7 @@
t.set_gid('leg_text_%d' % i)

# Save SVG in a fake file object.
f = StringIO()
f = BytesIO()
plt.savefig(f, format="svg")

# Create XML tree from the SVG file.
Expand Down
4 changes: 2 additions & 2 deletions examples/user_interfaces/svg_tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import matplotlib.pyplot as plt
import xml.etree.ElementTree as ET
from io import StringIO
from io import BytesIO

ET.register_namespace("", "http://www.w3.org/2000/svg")

Expand Down Expand Up @@ -72,7 +72,7 @@
ax.set_ylim(-30, 30)
ax.set_aspect('equal')

f = StringIO()
f = BytesIO()
plt.savefig(f, format="svg")

# --- Add interactivity ---
Expand Down