@@ -526,55 +526,3 @@ artists.
526
526
You may be able to work on separate figures from separate threads. However,
527
527
you must in that case use a *non-interactive backend * (typically Agg), because
528
528
most GUI backends *require * being run from the main thread as well.
529
-
530
- .. _howto-webapp :
531
-
532
- How to use Matplotlib in a web application server
533
- =================================================
534
-
535
- In general, the simplest solution when using Matplotlib in a web server is
536
- to completely avoid using pyplot (pyplot maintains references to the opened
537
- figures to make `~.matplotlib.pyplot.show ` work, but this will cause memory
538
- leaks unless the figures are properly closed). Since Matplotlib 3.1, one
539
- can directly create figures using the `.Figure ` constructor and save them to
540
- in-memory buffers. The following example uses Flask _, but other frameworks
541
- work similarly::
542
-
543
- import base64
544
- from io import BytesIO
545
-
546
- from flask import Flask
547
- from matplotlib.figure import Figure
548
-
549
- app = Flask(__name__)
550
-
551
- @app.route("/")
552
- def hello():
553
- # Generate the figure **without using pyplot**.
554
- fig = Figure()
555
- ax = fig.subplots()
556
- ax.plot([1, 2])
557
- # Save it to a temporary buffer.
558
- buf = BytesIO()
559
- fig.savefig(buf, format="png")
560
- # Embed the result in the html output.
561
- data = base64.b64encode(buf.getbuffer()).decode("ascii")
562
- return f"<img src='data:image/png;base64,{data}'/>"
563
-
564
- .. _Flask : http://flask.pocoo.org/
565
-
566
- When using Matplotlib versions older than 3.1, it is necessary to explicitly
567
- instantiate an Agg canvas; see e.g. :doc: `/gallery/user_interfaces/canvasagg `.
568
-
569
-
570
- .. _howto-click-maps :
571
-
572
- Clickable images for HTML
573
- -------------------------
574
-
575
- Andrew Dalke of `Dalke Scientific <http://www.dalkescientific.com >`_
576
- has written a nice `article
577
- <http://www.dalkescientific.com/writings/diary/archive/2005/04/24/interactive_html.html> `_
578
- on how to make html click maps with Matplotlib agg PNGs. We would
579
- also like to add this functionality to SVG. If you are interested in
580
- contributing to these efforts that would be great.
0 commit comments