File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -661,11 +661,12 @@ or by saving to a file handle::
661661 fig.savefig(sys.stdout)
662662
663663Here is an example using `Pillow <http://python-imaging.github.io/ >`_.
664- First, the figure is saved to a StringIO object which is then fed to
664+ First, the figure is saved to a BytesIO object which is then fed to
665665Pillow for further processing::
666666
667- import StringIO, Image
668- imgdata = StringIO.StringIO()
667+ from io import BytesIO
668+ from PIL import Image
669+ imgdata = BytesIO()
669670 fig.savefig(imgdata, format='png')
670671 imgdata.seek(0) # rewind the data
671672 im = Image.open(imgdata)
Original file line number Diff line number Diff line change 5151ax .set_xlim (0. , 1. )
5252ax .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 ()
5757plt .savefig (f , format = "svg" )
5858
5959
Original file line number Diff line number Diff line change 4242
4343
4444# save
45- from io import StringIO
46- f = StringIO ()
45+ from io import BytesIO
46+ f = BytesIO ()
4747plt .savefig (f , format = "svg" )
4848
4949import xml .etree .cElementTree as ET
Original file line number Diff line number Diff line change 3535import numpy as np
3636import matplotlib .pyplot as plt
3737import xml .etree .ElementTree as ET
38- from io import StringIO
38+ from io import BytesIO
3939import json
4040
4141plt .rcParams ['svg.embed_char_paths' ] = 'none'
7676 t .set_gid ('leg_text_%d' % i )
7777
7878# Save SVG in a fake file object.
79- f = StringIO ()
79+ f = BytesIO ()
8080plt .savefig (f , format = "svg" )
8181
8282# Create XML tree from the SVG file.
Original file line number Diff line number Diff line change 2424
2525import matplotlib .pyplot as plt
2626import xml .etree .ElementTree as ET
27- from io import StringIO
27+ from io import BytesIO
2828
2929ET .register_namespace ("" , "http://www.w3.org/2000/svg" )
3030
7272ax .set_ylim (- 30 , 30 )
7373ax .set_aspect ('equal' )
7474
75- f = StringIO ()
75+ f = BytesIO ()
7676plt .savefig (f , format = "svg" )
7777
7878# --- Add interactivity ---
You can’t perform that action at this time.
0 commit comments