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

Skip to content

Commit c7a1aa0

Browse files
timhoffmImportanceOfBeingErnest
authored andcommitted
Document How-to figure empty (#15297)
1 parent eb9b0d5 commit c7a1aa0

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
@@ -1,7 +1,7 @@
11
.. _howto-faq:
22

33
******
4-
How-To
4+
How-to
55
******
66

77
.. contents::
@@ -10,8 +10,8 @@ How-To
1010

1111
.. _howto-plotting:
1212

13-
Plotting: howto
14-
===============
13+
How-to: Plotting
14+
================
1515

1616
.. _howto-datetime64:
1717

@@ -37,6 +37,36 @@ If you only want to use the `pandas` converter for `numpy.datetime64` values ::
3737

3838

3939

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

4272
Find all objects in a figure of a certain type
@@ -553,8 +583,8 @@ most GUI backends *require* being run from the main thread as well.
553583

554584
.. _howto-contribute:
555585

556-
Contributing: howto
557-
===================
586+
How-to: Contributing
587+
====================
558588

559589
.. _how-to-request-feature:
560590

@@ -641,8 +671,8 @@ or look at the open issues on github.
641671

642672
.. _howto-webapp:
643673

644-
Matplotlib in a web application server
645-
======================================
674+
How to use Matplotlib in a web application server
675+
=================================================
646676

647677
In general, the simplest solution when using Matplotlib in a web server is
648678
to completely avoid using pyplot (pyplot maintains references to the opened
@@ -694,8 +724,8 @@ contributing to these efforts that would be great.
694724

695725
.. _how-to-search-examples:
696726

697-
Search examples
698-
===============
727+
How to search for examples
728+
==========================
699729

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

0 commit comments

Comments
 (0)