File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33Embedding WebAgg
44================
55
6- This example demonstrates how to embed matplotlib WebAgg interactive
7- plotting in your own web application and framework. It is not
8- necessary to do all this if you merely want to display a plot in a
9- browser or use matplotlib's built-in Tornado-based server "on the
10- side".
6+ This example demonstrates how to embed Matplotlib WebAgg interactive plotting
7+ in your own web application and framework. It is not necessary to do all this
8+ if you merely want to display a plot in a browser or use Matplotlib's built-in
9+ Tornado-based server "on the side".
1110
1211The framework being used must support web sockets.
1312"""
1413
1514import io
15+ import mimetypes
1616
1717try :
1818 import tornado
@@ -138,20 +138,8 @@ class Download(tornado.web.RequestHandler):
138138
139139 def get (self , fmt ):
140140 manager = self .application .manager
141-
142- mimetypes = {
143- 'ps' : 'application/postscript' ,
144- 'eps' : 'application/postscript' ,
145- 'pdf' : 'application/pdf' ,
146- 'svg' : 'image/svg+xml' ,
147- 'png' : 'image/png' ,
148- 'jpeg' : 'image/jpeg' ,
149- 'tif' : 'image/tiff' ,
150- 'emf' : 'application/emf'
151- }
152-
153- self .set_header ('Content-Type' , mimetypes .get (fmt , 'binary' ))
154-
141+ self .set_header (
142+ 'Content-Type' , mimetypes .types_map .get (fmt , 'binary' ))
155143 buff = io .BytesIO ()
156144 manager .canvas .figure .savefig (buff , format = fmt )
157145 self .write (buff .getvalue ())
Original file line number Diff line number Diff line change 1515import errno
1616from io import BytesIO
1717import json
18+ import mimetypes
1819from pathlib import Path
1920import random
2021import sys
@@ -113,21 +114,8 @@ class Download(tornado.web.RequestHandler):
113114 def get (self , fignum , fmt ):
114115 fignum = int (fignum )
115116 manager = Gcf .get_fig_manager (fignum )
116-
117- # TODO: Move this to a central location
118- mimetypes = {
119- 'ps' : 'application/postscript' ,
120- 'eps' : 'application/postscript' ,
121- 'pdf' : 'application/pdf' ,
122- 'svg' : 'image/svg+xml' ,
123- 'png' : 'image/png' ,
124- 'jpeg' : 'image/jpeg' ,
125- 'tif' : 'image/tiff' ,
126- 'emf' : 'application/emf'
127- }
128-
129- self .set_header ('Content-Type' , mimetypes .get (fmt , 'binary' ))
130-
117+ self .set_header (
118+ 'Content-Type' , mimetypes .types_map .get (fmt , 'binary' ))
131119 buff = BytesIO ()
132120 manager .canvas .figure .savefig (buff , format = fmt )
133121 self .write (buff .getvalue ())
You can’t perform that action at this time.
0 commit comments