File tree Expand file tree Collapse file tree 2 files changed +10
-34
lines changed Expand file tree Collapse file tree 2 files changed +10
-34
lines changed Original file line number Diff line number Diff line change 3
3
Embedding WebAgg
4
4
================
5
5
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".
11
10
12
11
The framework being used must support web sockets.
13
12
"""
14
13
15
14
import io
15
+ import mimetypes
16
16
17
17
try :
18
18
import tornado
@@ -138,20 +138,8 @@ class Download(tornado.web.RequestHandler):
138
138
139
139
def get (self , fmt ):
140
140
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' ))
155
143
buff = io .BytesIO ()
156
144
manager .canvas .figure .savefig (buff , format = fmt )
157
145
self .write (buff .getvalue ())
Original file line number Diff line number Diff line change 15
15
import errno
16
16
from io import BytesIO
17
17
import json
18
+ import mimetypes
18
19
from pathlib import Path
19
20
import random
20
21
import sys
@@ -113,21 +114,8 @@ class Download(tornado.web.RequestHandler):
113
114
def get (self , fignum , fmt ):
114
115
fignum = int (fignum )
115
116
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' ))
131
119
buff = BytesIO ()
132
120
manager .canvas .figure .savefig (buff , format = fmt )
133
121
self .write (buff .getvalue ())
You can’t perform that action at this time.
0 commit comments