Show More
@@ -96,7 +96,10 b' def figsize(sizex, sizey):' | |||
|
96 | 96 | |
|
97 | 97 | |
|
98 | 98 | def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs): |
|
99 |
"""Print a figure to an image, and return the resulting |
|
|
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 | 104 | Any keyword args are passed to fig.canvas.print_figure, |
|
102 | 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 | 129 | bytes_io = BytesIO() |
|
127 | 130 | fig.canvas.print_figure(bytes_io, **kw) |
|
128 |
|
|
|
131 | data = bytes_io.getvalue() | |
|
132 | if fmt == 'svg': | |
|
133 | data = data.decode('utf-8') | |
|
134 | return data | |
|
129 | 135 | |
|
130 | 136 | def retina_figure(fig, **kwargs): |
|
131 | 137 | """format a figure as a pixel-doubled (retina) PNG""" |
@@ -58,7 +58,7 b' def test_figure_to_svg():' | |||
|
58 | 58 | ax.plot([1,2,3]) |
|
59 | 59 | plt.draw() |
|
60 | 60 | svg = pt.print_figure(fig, 'svg')[:100].lower() |
|
61 |
nt.assert_in( |
|
|
61 | nt.assert_in(u'doctype svg', svg) | |
|
62 | 62 | |
|
63 | 63 | def _check_pil_jpeg_bytes(): |
|
64 | 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