Skip to content

Commit edf8605

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: - contour_corner_mask_False the old implementation would white out some extra L-shaped areas between masked regions (particularly visible in the diff image). - 3d/contour3d: The order of the "contours" on the panes is a bit arbitrary, but note that previously on the left pane the white (medium) contour was drawn first, then overlaid with the blue (low) contour, then overlaid with the red (high) contour; the new image draws the contours more consistently in the order blue/white/red. - 3d/tricontour: The new draw order of the unfilled contours (on the left) is clearly better, with the highest contour (light green) drawn above the lower one (medium green). Limitations: - 3d contours used to rely on being able to set a different sort_zpos for each contour level; this change gets rid of that. Per the above it's not clear this is actually worse in practice...
1 parent ba55c52 commit edf8605

File tree

12 files changed

+516
-353
lines changed

12 files changed

+516
-353
lines changed
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

+1-4
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

+5-5
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)