8000 Merge pull request #18216 from QuLogic/combine-Axes-children · matplotlib/matplotlib@4085fc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4085fc7

Browse files
authored
Merge pull request #18216 from QuLogic/combine-Axes-children
MNT: Combine Axes.{lines,images,collections,patches,text,tables} into single list
2 parents f4cad33 + 8737ac3 commit 4085fc7

File tree

21 files changed

+6563
-5404
lines changed

21 files changed

+6563
-5404
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _Behavioral API Changes 3.5 - Axes children combined:
2+
3+
``Axes`` children are no longer separated by type
4+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5+
6+
Formerly, `.axes.Axes` children were separated by `.Artist` type, into sublists
7+
such as ``Axes.lines``. For methods that produced multiple elements (such as
8+
`.Axes.errorbar`), though individual parts would have similar *zorder*, this
9+
separation might cause them to be drawn at different times, causing
10+
inconsistent results when overlapping other Artists.
11+
12+
Now, the children are no longer separated by type, and the sublist properties
13+
are generated dynamically when accessed. Consequently, Artists will now always
14+
appear in the correct sublist; e.g., if `.axes.Axes.add_line` is called on a
15+
`.Patch`, it will be appear in the ``Axes.patches`` sublist, _not_
16+
``Axes.lines``. The ``Axes.add_*`` methods will now warn if passed an
17+
unexpected type.
18+
19+
Modification of the following sublists is still accepted, but deprecated:
20+
21+
* ``Axes.artists``
22+
* ``Axes.collections``
23+
* ``Axes.images``
24+
* ``Axes.lines``
25+
* ``Axes.patches``
26+
* ``Axes.tables``
27+
* ``Axes.texts``
28+
29+
To remove an Artist, use its `.Artist.remove` method. To add an Artist, use the
30+
corresponding ``Axes.add_*`` method.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Modification of ``Axes`` children sublists
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
See :ref:`Behavioral API Changes 3.5 - Axes children combined` for more
5+
information; modification of the following sublists is deprecated:
6+
7+
* ``Axes.artists``
8+
* ``Axes.collections``
9+
* ``Axes.images``
10+
* ``Axes.lines``
11+
* ``Axes.patches``
12+
* ``Axes.tables``
13+
* ``Axes.texts``
14+
15+
To remove an Artist, use its `.Artist.remove` method. To add an Artist, use the
16+
corresponding ``Axes.add_*`` method.
17+
18+
Passing incorrect types to ``Axes.add_*`` methods
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
21+
The ``Axes.add_*`` methods will now warn if passed an unexpected type. See
22+
their documentation for the types they expect.

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,9 @@ def axline(self, xy1, xy2=None, *, slope=None, **kwargs):
866866
if line.get_clip_path() is None:
867867
line.set_clip_path(self.patch)
868868
if not line.get_label():
869-
line.set_label(f"_line{len(self.lines)}")
870-
self.lines.append(line)
871-
line._remove_method = self.lines.remove
869+
line.set_label(f"_child{len(self._children)}")
870+
self._children.append(line)
871+
line._remove_method = self._children.remove
872872
self.update_datalim(datalim)
873873

874874
self._request_autoscale_view()

0 commit comments

Comments
 (0)
0