FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

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

Repository navigation

Add set_data for ContourSet - #32271

Merged
tacaswell merged 4 commits into
matplotlib:mainfrom
larsoner:contour-set-data
Oct 16, 2026
Merged

tacaswell merged 4 commits into
matplotlib:mainfrom
larsoner:contour-set-data

Conversation

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 commented Aug 31, 2026

Copy link
Copy Markdown
Member

I had actually been wondering if there’s a reason we didn’t have this. I think the common use case would be to fix the levels and update the data, so I agree there is no need to support updating levels here.

greglucas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice, I have also desired this capability.

Comment thread lib/matplotlib/contour.py Outdated
Comment thread lib/matplotlib/contour.py
Comment thread lib/matplotlib/cbook.py
Comment thread lib/matplotlib/cbook.py Outdated

Copy link
Copy Markdown
Contributor Author

Thanks for the review @greglucas , I pushed a commit and think I addressed your comments!

tacaswell merged commit 63cb8f4 into matplotlib:main Oct 16, 2026
41 checks passed
QuLogic added this to the v3.12.0 milestone Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

5 participants


Back | FazBrowse Home | New Git URL