10000 Fixes for file saving in webagg · htylab/matplotlib@ad341b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad341b4

Browse files
committed
Fixes for file saving in webagg
1 parent cdb6771 commit ad341b4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/backends/backend_webagg.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ def get(self, fignum, fmt):
197197

198198
self.set_header('Content-Type', mimetypes.get(fmt, 'binary'))
199199

200-
buff = io.BytesIO()
200+
# override fileno to raise AttributeError so PIL doesn't error
201+
class BytesIO(io.BytesIO):
202+
@property
203+
def fileno(self):
204+
raise AttributeError
205+
206+
buff = BytesIO()
201207
manager.canvas.print_figure(buff, format=fmt)
202208
self.write(buff.getvalue())
203209

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ def get_javascript(cls, stream=None):
403403
for filetype, ext in sorted(FigureCanvasWebAggCore.
404404
get_supported_filetypes_grouped().
405405
items()):
406-
extensions.append(ext[0])
406+
if not ext[0] == 'pgf': # pgf does not support BytesIO
407+
extensions.append(ext[0])
407408
output.write("mpl.extensions = {0};\n\n".format(
408409
json.dumps(extensions)))
409410

0 commit comments

Comments
 (0)
0