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

MNT: Debug fig_size change after window close#29129

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

Draft
timhoffm wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromtimhoffm:fig-close

Conversation

timhoffm
Copy link
Member

@timhoffmtimhoffm commentedNov 12, 2024
edited
Loading

This is a minimal reproducer for a failure in the pipeline#29125 (comment).

Thetest_interactive_backend[toolmanager-MPLBACKEND=wxagg-BACKEND_DEPS=wx] fails in the pipeline at the subsequentassert result.getvalue() == result_after.getvalue() because the PNG data inresult andresult_after have different sizes (640x480) vs. (640x478); i.e.result_after is two pixels smaller. This stems from a changed fig size, as made explicit by the assert statement added here (precisely,fig.get_size_inches() changes fromnp.array([6.4, 4.8]) tonp.array([6.4, 4.78])).

I have not yet a clue why closing the figure window could change the figure size. Actually,showing the window changes the size, see below.


Note: reading the exception is a bit complicated because it happens in a called subprocess, but you'll find this somewhere in the middle of the traceback:

[...] assert tuple(fig.get_size_inches()) == tuple(size_inches), \\\nAssertionError: [6.4  4.78], [6.4 4.8]\n'

Update: This is the call stack that leads to the changed figure size:

  File "/home/tim/git/matplotlib/lib/matplotlib/tests/test_backends_interactive.py", line 223, in _test_interactive_impl    plt.show()  File "/home/tim/git/matplotlib/lib/matplotlib/pyplot.py", line 612, in show    return _get_backend_mod().show(*args, **kwargs)  File "/home/tim/git/matplotlib/lib/matplotlib/backend_bases.py", line 3534, in show    manager.show()  # Emits a warning for non-interactive backend.  File "/home/tim/git/matplotlib/lib/matplotlib/backends/backend_wx.py", line 1006, in show    self.frame.Show()  File "/home/tim/git/matplotlib/lib/matplotlib/backends/backend_wx.py", line 683, in _on_size    self.figure.set_size_inches(winch, hinch, forward=False)

Apparentlyshow() creates awx.EVT_SIZE, which is bound to_FigureCanvasWxBase._on_size(), and in there

size=self.GetClientSize()

returns the reduced height of 478.

@QuLogic
Copy link
Member

This is a result of#28838, which enabled the test everywhere, but at the time did not seem to be causing trouble.

However, I am seeing the problem with wxand Qt when building 3.10.0rc1 for Fedora. I though it was because I was running Xvfb at 680x480 and the figure didn't fit, but even at 800x600 it failed.

@timhoffm
Copy link
MemberAuthor

timhoffm commentedNov 13, 2024
edited
Loading

I've tried to move theshow() before thesavefig() to workaroundshow() altering figure size. While this fixes the previously failing tests, it seems to introduce issues in other tests. 😢

Anyway, the proper fix is to understand whyshow() changes the figure size - it should not do that.


I've also tried to produce a minimal example:

import matplotlibimport matplotlib.pyplot as pltmatplotlib.use('wxagg')plt.rcParams['toolbar'] == 'toolmanager'fig = plt.figure()print(fig.get_size_inches())plt.show()# close manuallyprint(fig.get_size_inches())

But (in the same environment as for the tests) this does not change figsize, so the effect seems somehow related to the addmittedly complex test setup.

timhoffm added a commit to timhoffm/matplotlib that referenced this pull requestNov 13, 2024
Works around the failurematplotlib#29129. A proper analysisand resolution is still needed.
@timhoffmtimhoffm marked this pull request as draftDecember 18, 2024 18:57
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@timhoffm@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp