Show More
@@ -123,14 +123,18 b" def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs):" | |||||
123 | } |
|
123 | } | |
124 | # **kwargs get higher priority |
|
124 | # **kwargs get higher priority | |
125 | kw.update(kwargs) |
|
125 | kw.update(kwargs) | |
126 |
|
126 | |||
127 | bytes_io = BytesIO() |
|
127 | bytes_io = BytesIO() | |
|
128 | if fig.canvas is None: | |||
|
129 | from matplotlib.backend_bases import FigureCanvasBase | |||
|
130 | FigureCanvasBase(fig) | |||
|
131 | ||||
128 | fig.canvas.print_figure(bytes_io, **kw) |
|
132 | fig.canvas.print_figure(bytes_io, **kw) | |
129 | data = bytes_io.getvalue() |
|
133 | data = bytes_io.getvalue() | |
130 | if fmt == 'svg': |
|
134 | if fmt == 'svg': | |
131 | data = data.decode('utf-8') |
|
135 | data = data.decode('utf-8') | |
132 | return data |
|
136 | return data | |
133 |
|
137 | |||
134 | def retina_figure(fig, **kwargs): |
|
138 | def retina_figure(fig, **kwargs): | |
135 | """format a figure as a pixel-doubled (retina) PNG""" |
|
139 | """format a figure as a pixel-doubled (retina) PNG""" | |
136 | pngdata = print_figure(fig, fmt='retina', **kwargs) |
|
140 | pngdata = print_figure(fig, fmt='retina', **kwargs) |
@@ -248,3 +248,9 b' class TestPylabSwitch(object):' | |||||
248 | def test_no_gui_backends(): |
|
248 | def test_no_gui_backends(): | |
249 | for k in ['agg', 'svg', 'pdf', 'ps']: |
|
249 | for k in ['agg', 'svg', 'pdf', 'ps']: | |
250 | assert k not in pt.backend2gui |
|
250 | assert k not in pt.backend2gui | |
|
251 | ||||
|
252 | ||||
|
253 | def test_figure_no_canvas(): | |||
|
254 | fig = Figure() | |||
|
255 | fig.canvas = None | |||
|
256 | pt.print_figure(fig) |
General Comments 0
You need to be logged in to leave comments.
Login now