8000 Backport PR #15297: Document How-to figure empty · matplotlib/matplotlib@285efc3 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 285efc3

Browse files
timhoffmMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #15297: Document How-to figure empty
1 parent fcbdd19 commit 285efc3

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

doc/faq/howto_faq.rst

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. _howto-faq:
33

44
******
5-
How-To
5+
How-to
66
******
77

88
.. contents::
@@ -11,8 +11,8 @@ How-To
1111

1212
.. _howto-plotting:
1313

14-
Plotting: howto
15-
===============
14+
How-to: Plotting
15+
================
1616

1717
.. _howto-datetime64:
1818

@@ -38,6 +38,36 @@ If you only want to use the `pandas` converter for `datetime64` values ::
3838

3939

4040

41+
.. _howto-figure-empty:
42+
43+
Check whether a figure is empty
44+
-------------------------------
45+
Empty can actually mean different things. Does the figure contain any artists?
46+
Does a figure with an empty `~.axes.Axes` still count as empty? Is the figure
47+
empty if it was rendered pure white (there may be artists present, but they
48+
could be outside the drawing area or transparent)?
49+
50+
For the purpose here, we define empty as: "The figure does not contain any
51+
artists except it's background patch." The exception for the background is
52+
necessary, because by default every figure contains a `.Rectangle` as it's
53+
background patch. This definition could be checked via::
54+
55+
def is_empty(figure):
56+
"""
57+
Return whether the figure contains no Artists (other than the default
58+
background patch).
59+
"""
60+
contained_artists = figure.get_children()
61+
return len(contained_artists) <= 1
62+
63+
We've decided not to include this as a figure method because this is only one
64+
way of defining empty, and checking the above is only rarely necessary.
65+
Usually the user or program handling the figure know if they have added
66+
something to the figure.
67+
68+
Checking whether a figure would render empty cannot be reliably checked except
69+
by actually rendering the figure and investigating the rendered result.
70+
4171
.. _howto-findobj:
4272

4373
Find all objects in a figure of a certain type
@@ -549,8 +579,8 @@ GUI backends *require* being run from the main thread as well.
549579

550580
.. _howto-contribute:
551581

552-
Contributing: howto
553-
===================
582+
How-to: Contributing
583+
====================
554584

555585
.. _how-to-request-feature:
556586

@@ -637,8 +667,8 @@ or look at the open issues on github.
637667

638668
.. _howto-webapp:
639669

640-
Matplotlib in a web application server
641-
======================================
670+
How to use Matplotlib in a web application server
671+
=================================================
642672

643673
In general, the simplest solution when using Matplotlib in a web server is
644674
to completely avoid using pyplot (pyplot maintains references to the opened
@@ -690,8 +720,8 @@ contributing to these efforts that would be great.
690720

691721
.. _how-to-search-examples:
692722

693-
Search examples
694-
===============
723+
How to search for examples
724+
==========================
695725

696726
The nearly 300 code :ref:`examples-index` included with the Matplotlib
697727
source distribution are full-text searchable from the :ref:`search`

0 commit comments

Comments
 (0)
0