Skip to content

Commit 40cfef1

Browse files
committed
Merge pull request #6205 from mdboom/fix-stringio
Use io.BytesIO instead of io.StringIO in examples
1 parent e277f99 commit 40cfef1

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

doc/faq/howto_faq.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,12 @@ or by saving to a file handle::
632632
fig.savefig(sys.stdout)
633633

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

638-
import StringIO, Image
639-
imgdata = StringIO.StringIO()
638+
from io import BytesIO
639+
from PIL import Image
640+
imgdata = BytesIO()
640641
fig.savefig(imgdata, format='png')
641642
imgdata.seek(0) # rewind the data
642643
im = Image.open(imgdata)

examples/misc/svg_filter_line.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
ax.set_xlim(0., 1.)
5252
ax.set_ylim(0., 1.)
5353

54-
# save the figure as a string in the svg format.
55-
from io import StringIO
56-
f = StringIO()
54+
# save the figure as a bytes string in the svg format.
55+
from io import BytesIO
56+
f = BytesIO()
5757
plt.savefig(f, format="svg")
5858

5959

examples/misc/svg_filter_pie.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242

4343

4444
# save
45-
from io import StringIO
46-
f = StringIO()
45+
from io import BytesIO
46+
f = BytesIO()
4747
plt.savefig(f, format="svg")
4848

4949
import xml.etree.cElementTree as ET

examples/user_interfaces/svg_histogram.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import numpy as np
3636
import matplotlib.pyplot as plt
3737
import xml.etree.ElementTree as ET
38-
from io import StringIO
38+
from io import BytesIO
3939
import json
4040

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

7878
# Save SVG in a fake file object.
79-
f = StringIO()
79+
f = BytesIO()
8080
plt.savefig(f, format="svg")
8181

8282
# Create XML tree from the SVG file.

examples/user_interfaces/svg_tooltip.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import matplotlib.pyplot as plt
2626
import xml.etree.ElementTree as ET
27-
from io import StringIO
27+
from io import BytesIO
2828

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

@@ -72,7 +72,7 @@
7272
ax.set_ylim(-30, 30)
7373
ax.set_aspect('equal')
7474

75-
f = StringIO()
75+
f = BytesIO()
7676
plt.savefig(f, format="svg")
7777

7878
# --- Add interactivity ---

0 commit comments

Comments
 (0)