Skip to content

Navigation Menu

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 d43acd4

Browse filesBrowse files
committed
Move Axes.collections into hidden children attribute.
The collections can still be accessed via a read-only property, but now are combined with images, lines, patches, tables and texts for sorting and drawing purposes. There was a quite a bit more fallout from this one: * `streamplot` had to add the arrows after the line collection, so they would remain on top. Because `FancyArrowPatch` is created in display coordinates, this meant that their limits changed slightly, as adding the line collection would have re-adjusted the `Axes.transData`. * The `test_pre_transform_plotting` image needed to be regenerated because of the above limit change. I took this opportunity to clean up some of the previous keep-image-the-same hacks. * The `test_arrow_contains_point` test image now has 'contained' scatter points correctly over the arrows. * Tests in `test_patches.py` needed to be re-ordered slightly as they were checking alpha between collections and non-collection artists. * The `test_fancy` legend images needed to be regenerated because errorbars are correctly drawn as a group now.
1 parent c9661c3 commit d43acd4
Copy full SHA for d43acd4

File tree

Expand file treeCollapse file tree

12 files changed

+6141
-5292
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+6141
-5292
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+18-14Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
import numpy as np
1212

1313
import matplotlib as mpl
14+
import matplotlib.artist as martist
15+
import matplotlib.axis as maxis
1416
from matplotlib import cbook
1517
from matplotlib.cbook import _OrderedSet, _check_1d, index_of
16-
from matplotlib import docstring
18+
import matplotlib.collections as mcoll
1719
import matplotlib.colors as mcolors
20+
from matplotlib import docstring
21+
import matplotlib.font_manager as font_manager
22+
import matplotlib.image as mimage
1823
import matplotlib.lines as mlines
1924
import matplotlib.patches as mpatches
20-
import matplotlib.artist as martist
21-
import matplotlib.transforms as mtransforms
22-
import matplotlib.ticker as mticker
23-
import matplotlib.axis as maxis
25+
from matplotlib.rcsetup import cycler, validate_axisbelow
2426
import matplotlib.spines as mspines
25-
import matplotlib.font_manager as font_manager
2627
import matplotlib.table as mtable
2728
import matplotlib.text as mtext
28-
import matplotlib.image as mimage
29-
from matplotlib.rcsetup import cycler, validate_axisbelow
29+
import matplotlib.ticker as mticker
30+
import matplotlib.transforms as mtransforms
3031

3132
_log = logging.getLogger(__name__)
3233

@@ -1109,7 +1110,6 @@ def cla(self):
11091110
self.child_axes = []
11101111
self._current_image = None # strictly for pyplot via _sci, _gci
11111112
self.legend_ = None
1112-
self.collections = [] # collection.Collection instances
11131113
self.containers = []
11141114

11151115
self.grid(False) # Disable grid on init to use rcParameter
@@ -1177,6 +1177,11 @@ def cla(self):
11771177

11781178
self.stale = True
11791179

1180+
@property
1181+
def collections(self):
1182+
return tuple(a for a in self._children
1183+
if isinstance(a, mcoll.Collection))
1184+
11801185
@property
11811186
def images(self):
11821187
return tuple(a for a in self._children
@@ -1947,13 +1952,13 @@ def add_child_axes(self, ax):
19471952

19481953
def add_collection(self, collection, autolim=True):
19491954
"""
1950-
Add a `~.Collection` to the axes' collections; return the collection.
1955+
Add a `~.Collection` to the Axes; return the collection.
19511956
"""
19521957
label = collection.get_label()
19531958
if not label:
1954-
collection.set_label('_collection%d' % len(self.collections))
1955-
self.collections.append(collection)
1956-
collection._remove_method = self.collections.remove
1959+
collection.set_label(f'_collection{len(self._children)}')
1960+
self._children.append(collection)
1961+
collection._remove_method = self._children.remove
19571962
self._set_artist_props(collection)
19581963

19591964
if collection.get_clip_path() is None:
@@ -4074,7 +4079,6 @@ def format_deltas(key, dx, dy):
40744079
def get_children(self):
40754080
# docstring inherited.
40764081
return [
4077-
*self.collections,
40784082
*self._children,
40794083
*self.artists,
40804084
*self.spines.values(),

‎lib/matplotlib/streamplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/streamplot.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
211211

212212
p = patches.FancyArrowPatch(
213213
arrow_tail, arrow_head, transform=transform, **arrow_kw)
214-
axes.add_patch(p)
215214
arrows.append(p)
216215

217216
lc = mcollections.LineCollection(
@@ -223,9 +222,13 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None,
223222
lc.set_cmap(cmap)
224223
lc.set_norm(norm)
225224
axes.add_collection(lc)
226-
axes.autoscale_view()
227225

228226
ac = matplotlib.collections.PatchCollection(arrows)
227+
# Adding the collection itself is broken; see #2341.
228+
for p in arrows:
229+
axes.add_patch(p)
230+
231+
axes.autoscale_view()
229232
stream_container = StreamplotSet(lc, ac)
230233
return stream_container
231234

Binary file not shown.
Loading

‎lib/matplotlib/tests/baseline_images/test_legend/fancy.svg

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/baseline_images/test_legend/fancy.svg
+326-310Lines changed: 326 additions & 310 deletions
Loading
Loading
Binary file not shown.
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.