Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6e6bda

Browse files
meeseeksmachinetimhoffm
authored andcommitted
Backport PR #12257: Document standard backends in matplotlib.use() (#12400)
1 parent 6f0cbd4 commit e6e6bda

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

lib/matplotlib/__init__.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,16 +1323,23 @@ def use(arg, warn=True, force=False):
13231323
"""
13241324
Set the matplotlib backend to one of the known backends.
13251325
1326-
To find out which backend is currently set, see
1327-
:func:`matplotlib.get_backend`.
1328-
1329-
13301326
Parameters
13311327
----------
13321328
arg : str
13331329
The backend to switch to. This can either be one of the
1334-
'standard' backend names or a string of the form
1335-
``module://my.module.name``. This value is case-insensitive.
1330+
'standard' backend names:
1331+
1332+
- interactive backends:
1333+
GTK3Agg, GTK3Cairo, MacOSX, nbAgg,
1334+
Qt4Agg, Qt4Cairo, Qt5Agg, Qt5Cairo,
1335+
TkAgg, TkCairo, WebAgg, WX, WXAgg, WXCairo
1336+
1337+
- non-interactive backends:
1338+
agg, cairo, pdf, pgf, ps, svg, template
1339+
1340+
or a string of the form: ``module://my.module.name``.
1341+
1342+
Note: Standard backend names are case-insensitive here.
13361343
13371344
warn : bool, optional
13381345
If True, warn if this is called after pyplot has been imported
@@ -1344,7 +1351,10 @@ def use(arg, warn=True, force=False):
13441351
If True, attempt to switch the backend. This defaults to
13451352
False.
13461353
1347-
1354+
See Also
1355+
--------
1356+
:ref:`backends`
1357+
matplotlib.get_backend
13481358
"""
13491359
name = validate_backend(arg)
13501360

@@ -1383,7 +1393,13 @@ def use(arg, warn=True, force=False):
13831393

13841394

13851395
def get_backend():
1386-
"""Return the name of the current backend."""
1396+
"""
1397+
Return the name of the current backend.
1398+
1399+
See Also
1400+
--------
1401+
matplotlib.use
1402+
"""
13871403
return rcParams['backend']
13881404

13891405

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import matplotlib
2+
import matplotlib.rcsetup
3+
4+
5+
def test_use_doc_standard_backends():
6+
"""
7+
Test that the standard backends mentioned in the docstring of
8+
matplotlib.use() are the same as in matplotlib.rcsetup.
9+
"""
10+
def parse(key):
11+
backends = []
12+
for line in matplotlib.use.__doc__.split(key)[1].split('\n'):
13+
if not line.strip():
14+
break
15+
backends += [e.strip() for e in line.split(',') if e]
16+
return backends
17+
18+
assert (set(parse('- interactive backends:\n')) ==
19+
set(matplotlib.rcsetup.interactive_bk))
20+
assert (set(parse('- non-interactive backends:\n')) ==
21+
set(matplotlib.rcsetup.non_interactive_bk))

tutorials/introductory/usage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ def my_plotter(ax, data1, data2, param_dict):
284284
# Again, for these simple examples this style seems like overkill, however
285285
# once the graphs get slightly more complex it pays off.
286286
#
287+
#
288+
# .. _backends:
289+
#
287290
# Backends
288291
# ========
289292
#

0 commit comments

Comments
 (0)