forked from matplotlib/matplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
To get contour labelling working with its special transforms, Cartopy has a workaround where it replaces all the paths on the ContourSet with transformed versions. This currently looks like
paths = cs.get_paths()
paths[:] = transformed_pathswhich doesn’t smell very good.
Proposed solution
The above would smell better as
cs.set_paths(transformed_paths)Additional context
I'm actually a bit confused as to why Collection.set_paths raises NotImplementedError instead of setting self._paths (which is what Collection.get_paths already returns).
Thanks @anntzer. So would it be enough to just copy what PathCollection has?
Untested, but possibly yes?
Specification (from research)
- Add
ContourSet.set_paths(paths)to replace the internal list ofmatplotlib.path.Pathobjects used for drawing and labeling. - Validation:
pathsmust be a sequence ofPathinstances.- If
self._pathsexists,len(paths)must matchlen(self._paths)to preserve style/level mapping.
- Behavior:
- Assign
self._paths = list(paths). - If present, clear deprecated split-collections cache (e.g.,
del self._old_style_split_collections). - Mark
self.stale = True. - No implicit transform application; caller supplies paths in the coordinate system of
cs.get_transform().
- Assign
- Placement:
- Implement in
lib/matplotlib/contour.pywithin classContourSet. - Add typing stub in
lib/matplotlib/contour.pyi.
- Implement in
- Tests:
- Replacing paths should not crash and should mark
.stale. - Labeling (
clabel) works with transformed paths. - Existing behavior unchanged when not calling
set_paths.
- Replacing paths should not crash and should mark
This Issue tracks task ID: 285.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels