Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Blocked set_clim() callbacks to prevent inconsistent state (#29522)#29590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

prafulgulani
Copy link
Contributor

closes#29522

  • Why is this change necessary? What problem does it solve? What is the reasoning for this implementation?
    Previously when norm's limits were updated, self.changed() was called through the callbacks attached to the norm, these callbacks were fired immediately leading to inconsistent state and causing the bug.
    This change blocks the immediate callbacks and emits a update signal after both the limits have been set.

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

Copy link
Contributor

@greglucasgreglucas left a comment

Choose a reason for hiding this comment

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

Can you add a test for this?

This is still a band-aid over the underlying problem in my opinion, but probably worth adding still. This won't help people setting vmin/vmax manually outside of theset_clim() call.

The issue is still with who should own the updates to the norm, the colorbar or the norm setting and does one take precedence over the other. My guess is that we need to try and push the colorbar's auto-expansion logic up into the initializer somehow rather than at draw time.

@prafulgulani
Copy link
ContributorAuthor

prafulgulani commentedFeb 9, 2025
edited
Loading

Not sure if the test would meet the expectations because this is my first open-source contribution, can I give it a try?
Just to be sure I need to write a test which tests if the set_clim() function now updates to new limits correctly right?

@greglucas
Copy link
Contributor

@prafulgulani, yes please do give it a shot and if you have any questions feel free to ask here.

You want to make sure that only one "changed" signal gets sent when callingset_clim(). Here is an example test we already have for testing the callbacks from the norm directly. You should add a similarmock.assert_called_once() to your test.

deftest_norm_callback():
increment=unittest.mock.Mock(return_value=None)
norm=mcolors.Normalize()
norm.callbacks.connect('changed',increment)
# Haven't updated anything, so call count should be 0
assertincrement.call_count==0
# Now change vmin and vmax to test callbacks
norm.vmin=1
assertincrement.call_count==1
norm.vmax=5
assertincrement.call_count==2
# callback shouldn't be called if setting to the same value
norm.vmin=1
assertincrement.call_count==2
norm.vmax=5
assertincrement.call_count==2
# We only want autoscale() calls to send out one update signal
increment.call_count=0
norm.autoscale([0,1,2])
assertincrement.call_count==1

@prafulgulaniprafulgulaniforce-pushed thebugfix-for-issue-29522 branch 2 times, most recently from256882f to295e5b7CompareFebruary 12, 2025 05:40
@prafulgulaniprafulgulani marked this pull request as ready for reviewFebruary 12, 2025 09:02
Copy link
Contributor

@greglucasgreglucas left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for updating this!

Note to second reviewer, please squash merge.

Comment on lines 1625 to 1626
plt.close(fig)

Copy link
Member

Choose a reason for hiding this comment

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

Not necessary; tests always close figures.

Suggested change
plt.close(fig)

Comment on lines 1616 to 1617
# Initial callback count should be zero
assert callback.call_count == 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Initial callback count should be zero
assertcallback.call_count==0
callback.assert_not_called()

@github-actionsgithub-actionsbot added topic: color/color & colormaps topic: images topic: axes CI: Run cibuildwheelRun wheel building tests on a PR Documentation: examplesfiles in galleries/examples Documentation: devdocsfiles in doc/devel Documentation: user guidefiles in galleries/users_explain or doc/users labelsFeb 22, 2025
@github-actionsgithub-actionsbot removed topic: color/color & colormaps topic: images topic: axes CI: Run cibuildwheelRun wheel building tests on a PR Documentation: examplesfiles in galleries/examples Documentation: devdocsfiles in doc/devel Documentation: user guidefiles in galleries/users_explain or doc/users labelsFeb 22, 2025
@timhoffmtimhoffm added this to thev3.10.2 milestoneFeb 28, 2025
@timhoffmtimhoffm merged commit07371db intomatplotlib:mainFeb 28, 2025
42 of 45 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestFeb 28, 2025
@timhoffm
Copy link
Member

Thanks@prafulgulani and congratulations on your first contribution to Matploblib! 🎉

prafulgulani reacted with laugh emoji

@prafulgulaniprafulgulani deleted the bugfix-for-issue-29522 branchFebruary 28, 2025 15:34
@prafulgulaniprafulgulani restored the bugfix-for-issue-29522 branchFebruary 28, 2025 15:34
@prafulgulaniprafulgulani deleted the bugfix-for-issue-29522 branchFebruary 28, 2025 15:35
@QuLogicQuLogic moved this fromWaiting for author toMerged inFirst Time ContributorsFeb 28, 2025
QuLogic added a commit that referenced this pull requestFeb 28, 2025
…590-on-v3.10.xBackport PR#29590 on branch v3.10.x (Blocked set_clim() callbacks to prevent inconsistent state (#29522))
@ksundenksunden mentioned this pull requestMay 9, 2025
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@timhoffmtimhoffmtimhoffm approved these changes

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Labels
None yet
Projects
Milestone
v3.10.3
Development

Successfully merging this pull request may close these issues.

[Bug]: Image color limits not correctly updated with set_clim() IFF color bar present AND new norm.vmin > old norm.vmax
4 participants
@prafulgulani@greglucas@timhoffm@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp