Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a draw during show for macos backend #27955

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

ksunden
Copy link
Member

@ksunden ksunden commented Mar 20, 2024

Without this a stale figure is shown

PR summary

This is basically the same concept as what happens just before show in plt.pause.

Essentially, there is nothing in the macos backend that actually causes a stale figure to be redrawn on show.
Other backends (qt, tk in particular, but likely others) seem to be saved by the fact that a resize event is triggered upon show, but macos does not do the same.

Other ideas considered, would be to do this in plt.show (which would perhaps leave out some other mechanisms, such as mpl-gui) or to try and do this in backend_bases (which is hard because most do not call super).
Could also leave out the condition and just always call draw_idle.

closes #27953

PR checklist

Without this a stale figure is shown
@QuLogic QuLogic added this to the v3.8.4 milestone Mar 21, 2024
@QuLogic QuLogic requested a review from greglucas March 21, 2024 00:27
Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

Thanks for the pointer about this needing to be run in a terminal and not a script. I can reproduce the original issue that way.

This fixes the issue, so has my approval and is good to go in. But I am still not sure whether there is a deeper issue here with the way we are setting the interrupt handling that this is just covering up in a sense by forcing another event through.

In the __init__ method, we are actually following the call to self.show() with a draw_idle(). I'm wondering if we can either remove that call now, or if we should just be calling draw_idle() here regardless of whether we are stale or not like above.

if mpl.is_interactive():
self.show()
self.canvas.draw_idle()

@ksunden
Copy link
Member Author

ksunden commented Apr 1, 2024

Ping for second review here, I'd like to get this in for 3.8.4, which I would like to get out soon for np2 reasons.

I'm not too concerned about potentially doubling up draw_idle requests here, as they are intentionally pretty cheap in the first place. I am more interested in getting the fix in than tracking down if other calls could possibly be omitted.

I think it is likely correct that we could omit the call in __init__ (even with the stale check), but also think the performance concern is quite minimal and am not 100% sure. (I would be pretty sure if we omitted the stale check, but not clear to me which would be "better")

@tacaswell tacaswell merged commit d0faf22 into matplotlib:main Apr 3, 2024
@ksunden ksunden deleted the macos_show_draw branch April 3, 2024 19:11
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 3, 2024
QuLogic added a commit that referenced this pull request Apr 3, 2024
…955-on-v3.8.x

Backport PR #27955 on branch v3.8.x (Add a draw during show for macos backend)
@ksunden ksunden mentioned this pull request Apr 4, 2024
5 tasks
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.

[Bug]: Pyplot can no longer set axes properties
4 participants