Add set_data for ContourSet by larsoner · Pull Request #32271 · matplotlib/matplotlib · GitHub
Skip to content

Add set_data for ContourSet - #32271

Open
larsoner wants to merge 2 commits into
matplotlib:mainfrom
larsoner:contour-set-data
Open

Add set_data for ContourSet#32271
larsoner wants to merge 2 commits into
matplotlib:mainfrom
larsoner:contour-set-data

Conversation

@larsoner

Copy link
Copy Markdown
Contributor

PR summary

Covering the actual use case for MNE-Python I was investigating when I hit #32264 : needing to update contours inside an animation. This PR adds ContourSet.set_data so that contours can be blitted properly rather than removed and readded.

This is really "issue as PR" -- I wasn't sure how many lines of code would be needed to make it work, so I figured I'd just check by implementing the changes... So I'm happy to close if this isn't wanted or refactor heavily if there is a better way, etc. It didn't end up being so bad since _process_args could be reused -- most of the new lines are unit tests actually. Related issues:

One intentional omission is support for setting levels. I think that should be a follow-up PR if desired -- it interacts with colorbars etc. which is a harder problem. (And maybe should be solved more generally with a .set_levels instead!) Also fixes a small TriContour bug I encountered when adding a **kwargs check (see lib/matplotlib/tri/_tricontour.py). I also added a helper to reset the object state in case the set_data fails after some attributes are already set (which can happen inside _process_args), put in cbook so that other Artists could potentially use it down the line.

AI Disclosure

I had Claude Opus 5 draft the code changes. I iterated through them until it looked like what I would have produced on my own (with better/more complete testing actually).

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • Plotting related features are demonstrated in an example
  • New features and API changes have release notes
  • Documentation complies with general and docstring guidelines

@rcomer

rcomer commented Aug 31, 2026

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants