File tree 5 files changed +13
-12
lines changed
5 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -632,11 +632,12 @@ or by saving to a file handle::
632
632
fig.savefig(sys.stdout)
633
633
634
634
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
636
636
Pillow for further processing::
637
637
638
- import StringIO, Image
639
- imgdata = StringIO.StringIO()
638
+ from io import BytesIO
639
+ from PIL import Image
640
+ imgdata = BytesIO()
640
641
fig.savefig(imgdata, format='png')
641
642
imgdata.seek(0) # rewind the data
642
643
im = Image.open(imgdata)
Original file line number Diff line number Diff line change 51
51
ax .set_xlim (0. , 1. )
52
52
ax .set_ylim (0. , 1. )
53
53
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 ()
57
57
plt .savefig (f , format = "svg" )
58
58
59
59
Original file line number Diff line number Diff line change 42
42
43
43
44
44
# save
45
- from io import StringIO
46
- f = StringIO ()
45
+ from io import BytesIO
46
+ f = BytesIO ()
47
47
plt .savefig (f , format = "svg" )
48
48
49
49
import xml .etree .cElementTree as ET
Original file line number Diff line number Diff line change 35
35
import numpy as np
36
36
import matplotlib .pyplot as plt
37
37
import xml .etree .ElementTree as ET
38
- from io import StringIO
38
+ from io import BytesIO
39
39
import json
40
40
41
41
plt .rcParams ['svg.embed_char_paths' ] = 'none'
76
76
t .set_gid ('leg_text_%d' % i )
77
77
78
78
# Save SVG in a fake file object.
79
- f = StringIO ()
79
+ f = BytesIO ()
80
80
plt .savefig (f , format = "svg" )
81
81
82
82
# Create XML tree from the SVG file.
Original file line number Diff line number Diff line change 24
24
25
25
import matplotlib .pyplot as plt
26
26
import xml .etree .ElementTree as ET
27
- from io import StringIO
27
+ from io import BytesIO
28
28
29
29
ET .register_namespace ("" , "http://www.w3.org/2000/svg" )
30
30
72
72
ax .set_ylim (- 30 , 30 )
73
73
ax .set_aspect ('equal' )
74
74
75
- f = StringIO ()
75
+ f = BytesIO ()
76
76
plt .savefig (f , format = "svg" )
77
77
78
78
# --- Add interactivity ---
You can’t perform that action at this time.
0 commit comments