##// END OF EJS Templates
print_figure returns unicode for svg
MinRK -
Show More
@@ -96,7 +96,10 b' def figsize(sizex, sizey):'
96
96
97
97
98 def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs):
98 def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs):
99 """Print a figure to an image, and return the resulting bytes
99 """Print a figure to an image, and return the resulting file data
100
101 Returned data will be bytes unless ``fmt='svg'``,
102 in which case it will be unicode.
100
103
101 Any keyword args are passed to fig.canvas.print_figure,
104 Any keyword args are passed to fig.canvas.print_figure,
102 such as ``quality`` or ``bbox_inches``.
105 such as ``quality`` or ``bbox_inches``.
@@ -125,7 +128,10 b" def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs):"
125
128
126 bytes_io = BytesIO()
129 bytes_io = BytesIO()
127 fig.canvas.print_figure(bytes_io, **kw)
130 fig.canvas.print_figure(bytes_io, **kw)
128 return bytes_io.getvalue()
131 data = bytes_io.getvalue()
132 if fmt == 'svg':
133 data = data.decode('utf-8')
134 return data
129
135
130 def retina_figure(fig, **kwargs):
136 def retina_figure(fig, **kwargs):
131 """format a figure as a pixel-doubled (retina) PNG"""
137 """format a figure as a pixel-doubled (retina) PNG"""
@@ -58,7 +58,7 b' def test_figure_to_svg():'
58 ax.plot([1,2,3])
58 ax.plot([1,2,3])
59 plt.draw()
59 plt.draw()
60 svg = pt.print_figure(fig, 'svg')[:100].lower()
60 svg = pt.print_figure(fig, 'svg')[:100].lower()
61 nt.assert_in(b'doctype svg', svg)
61 nt.assert_in(u'doctype svg', svg)
62
62
63 def _check_pil_jpeg_bytes():
63 def _check_pil_jpeg_bytes():
64 """Skip if PIL can't write JPEGs to BytesIO objects"""
64 """Skip if PIL can't write JPEGs to BytesIO objects"""
General Comments 0
You need to be logged in to leave comments. Login now