Skip to content

Commit bc35b6d

Browse files
committed
Update description of web application server example.
1 parent d872350 commit bc35b6d

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

doc/faq/howto_faq.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ the desired format::
433433

434434
.. seealso::
435435

436-
:ref:`howto-webapp` for information about running matplotlib inside
437-
of a web application.
436+
:doc:`/gallery/user_interfaces/web_application_server_sgskip` for
437+
information about running matplotlib inside of a web application.
438438

439439
.. _howto-show:
440440

examples/user_interfaces/web_application_server_sgskip.py

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
"""
2-
.. _howto-webapp:
2+
=============================================
3+
Embedding in a web application server (Flask)
4+
=============================================
35
4-
=================================================
5-
How to use Matplotlib in a web application server
6-
=================================================
6+
When using Matplotlib in a web server it is strongly recommended to not use
7+
pyplot (pyplot maintains references to the opened figures to make
8+
`~.matplotlib.pyplot.show` work, but this will cause memory leaks unless the
9+
figures are properly closed).
710
8-
In general, the simplest solution when using Matplotlib in a web server is
9-
to completely avoid using pyplot (pyplot maintains references to the opened
10-
figures to make `~.matplotlib.pyplot.show` work, but this will cause memory
11-
leaks unless the figures are properly closed). Since Matplotlib 3.1, one
12-
can directly create figures using the `.Figure` constructor and save them to
13-
in-memory buffers. The following example uses Flask_, but other frameworks
14-
work similarly:
11+
Since Matplotlib 3.1, one can directly create figures using the `.Figure`
12+
constructor and save them to in-memory buffers. In older versions, it was
13+
necessary to explicitly instantiate an Agg canvas (see e.g.
14+
:doc:`/gallery/user_interfaces/canvasagg`).
1515
16-
.. _Flask: http://flask.pocoo.org/
16+
The following example uses Flask_, but other frameworks work similarly:
17+
18+
.. _Flask: https://flask.palletsprojects.com
1719
1820
"""
1921

@@ -39,14 +41,10 @@ def hello():
3941
data = base64.b64encode(buf.getbuffer()).decode("ascii")
4042
return f"<img src='data:image/png;base64,{data}'/>"
4143

42-
# %%
43-
# When using Matplotlib versions older than 3.1, it is necessary to explicitly
44-
# instantiate an Agg canvas;
45-
# see e.g. :doc:`/gallery/user_interfaces/canvasagg`.
44+
#############################################################################
4645
#
47-
# Note: This script should be run using the
46+
# Since the above code is a Flask application, it should be run using the
4847
# `flask command-line tool <https://flask.palletsprojects.com/en/master/cli/>`_
49-
# since it is a Flask application.
5048
# Assuming that the working directory contains this script:
5149
#
5250
# Unix-like systems
@@ -62,7 +60,6 @@ def hello():
6260
# set FLASK_APP=web_application_server_sgskip
6361
# flask run
6462
#
65-
# .. _howto-click-maps:
6663
#
6764
# Clickable images for HTML
6865
# -------------------------

tutorials/introductory/usage.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,9 @@ def my_plotter(ax, data1, data2, param_dict):
364364
# Linux package named ``python-tk`` (or similar).
365365
#
366366
# If, however, you want to write graphical user interfaces, or a web
367-
# application server (:ref:`howto-webapp`), or need a better
368-
# understanding of what is going on, read on. To make things a little
367+
# application server
368+
# (:doc:`/gallery/user_interfaces/web_application_server_sgskip`), or need a
369+
# better understanding of what is going on, read on. To make things a little
369370
# more customizable for graphical user interfaces, Matplotlib separates
370371
# the concept of the renderer (the thing that actually does the drawing)
371372
# from the canvas (the place where the drawing goes). The canonical

0 commit comments

Comments
 (0)