Skip to content

Commit b7623b2

Browse files
committed
Turn ContourSet into a standard Collection artist.
Keep (some) backcompat by making access to ContourSet.collection trigger the self-replacement of the ContourSet by the old-style list of PathCollections. The baseline images are slighly shifted, but the new images actually look more correct; see e.g. contour_corner_mask_False.png where the old ("-expected.png") implementation would white out some extra L-shaped areas between masked regions (particularly visible in the diff image).
1 parent ba55c52 commit b7623b2

File tree

6 files changed

+448
-274
lines changed

6 files changed

+448
-274
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
``ContourSet.collections``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated. `.ContourSet` is now implemented as a single `.Collection` of paths,
4+
each path corresponding to a contour level, possibly including multiple unconnected
5+
components.
6+
7+
During the deprecation period, accessing ``ContourSet.collections`` will revert the
8+
current ContourSet instance to the old object layout, with a separate `.PathCollection`
9+
per contour level.

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,10 +2179,7 @@ def _sci(self, im):
21792179
_api.check_isinstance(
21802180
(mpl.contour.ContourSet, mcoll.Collection, mimage.AxesImage),
21812181
im=im)
2182-
if isinstance(im, mpl.contour.ContourSet):
2183-
if im.collections[0] not in self._children:
2184-
raise ValueError("ContourSet must be in current Axes")
2185-
elif im not in self._children:
2182+
if im not in self._children:
21862183
raise ValueError("Argument must be an image, collection, or "
21872184
"ContourSet in this Axes")
21882185
self._current_image = im

lib/matplotlib/colorbar.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,15 @@ def add_lines(self, *args, **kwargs):
767767
lambda self, levels, colors, linewidths, erase=True: locals()],
768768
self, *args, **kwargs)
769769
if "CS" in params:
770-
self, CS, erase = params.values()
771-
if not isinstance(CS, contour.ContourSet) or CS.filled:
770+
self, cs, erase = params.values()
771+
if not isinstance(cs, contour.ContourSet) or cs.filled:
772772
raise ValueError("If a single artist is passed to add_lines, "
773773
"it must be a ContourSet of lines")
774774
# TODO: Make colorbar lines auto-follow changes in contour lines.
775775
return self.add_lines(
776-
CS.levels,
777-
CS.to_rgba(CS.cvalues, CS.alpha),
778-
[coll.get_linewidths()[0] for coll in CS.collections],
776+
cs.levels,
777+
cs.to_rgba(cs.cvalues, cs.alpha),
778+
cs.get_linewidths(),
779779
erase=erase)
780780
else:
781781
self, levels, colors, linewidths, erase = params.values()

0 commit comments

Comments
 (0)