Skip to content

Wrong figure height after set_size_inches within event handler #10083

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

Closed
bwohlberg opened this issue Dec 24, 2017 · 1 comment · Fixed by #16929 or #16972
Closed

Wrong figure height after set_size_inches within event handler #10083

bwohlberg opened this issue Dec 24, 2017 · 1 comment · Fixed by #16929 or #16972
Labels
Milestone

Comments

@bwohlberg
Copy link

Bug report

Bug summary

When calling set_size_inches within an event handler, the new figure width is as requested, but the new height is not. This occurs with the TkAgg backend, but not the Qt5Agg backend (which suggests that this issue may not be related to #7302, since that issue is also reported to occur with Qt5Agg).

Code for reproduction

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8, 6))
def press(event):
    print('Before resize, size is ', fig.get_size_inches())
    sz = 1.1 * fig.get_size_inches()
    print('Size will be set to ', sz)
    fig.set_size_inches(sz, forward=True)
    fig.canvas.draw()
    print('After resize, size is ', fig.get_size_inches())
fig.canvas.mpl_connect('key_press_event', press)
fig.show()

input()

Pressing any key while the cursor is within the figure will attempt to resize the figure. The requested and actual sizes are printed to the console. If

import matplotlib
matplotlib.use('Qt5Agg')

is added at the start of this example, resizing behaves as expected.

Matplotlib version

  • Operating system: Ubuntu 16.04 64 bit
  • Matplotlib version: 2.1.1 (installed with pip)
  • Matplotlib backend: TkAgg
  • Python version: 3.5 (Ubuntu packaged version)
@tacaswell tacaswell added this to the v2.2 milestone Dec 24, 2017
@tacaswell
Copy link
Member

This is likely the same issue, on changing the size of the figure we change the size of the window to fit the figure + the toolbar and on window resize adjust the figure to the space it actually has. I suspect that the issue is we are incorrectly accounting for the toolbar size (which fits with it being backend dependent as the exact details of that logic is GUI framework dependent.

QuLogic added a commit to QuLogic/matplotlib that referenced this issue Mar 27, 2020
Resizing the figure directly does not account for the toolbar, so
figures are actually a little shorter than they should be. The recent
change to `Text.get_window_extent` some how causes this to actually get
reflected in the Matplotlib figure size, which cycles back to Tk and
shrinks the window. However, this can be triggered by other calls to
`Figure.set_size_inches` as noted in the fixed issues.

Fixes matplotlib#10083.
Fixes matplotlib#10566.
Fixes matplotlib#16926.
@QuLogic QuLogic modified the milestones: needs sorting, v3.2.2 Mar 27, 2020
QuLogic added a commit to QuLogic/matplotlib that referenced this issue Mar 31, 2020
Previously, it was the window that was resized to the intended size,
thus making the canvas smaller by the toolbar height.

Fixes matplotlib#10083 for GTK3.
Fixes matplotlib#10566 for GTK3.
@QuLogic QuLogic mentioned this issue Mar 31, 2020
2 tasks
QuLogic added a commit to QuLogic/matplotlib that referenced this issue Mar 31, 2020
Previously, it was the window that was resized to the intended size,
thus making the canvas smaller by the toolbar height.

Fixes matplotlib#10083 for GTK3.
Fixes matplotlib#10566 for GTK3.
QuLogic added a commit to QuLogic/matplotlib that referenced this issue Mar 31, 2020
Previously, it was the window that was resized to the intended size,
thus making the canvas smaller by the toolbar height.

Fixes matplotlib#10083 for GTK3.
Fixes matplotlib#10566 for GTK3.
toddrjen pushed a commit to toddrjen/matplotlib that referenced this issue Apr 6, 2020
Resizing the figure directly does not account for the toolbar, so
figures are actually a little shorter than they should be. The recent
change to `Text.get_window_extent` some how causes this to actually get
reflected in the Matplotlib figure size, which cycles back to Tk and
shrinks the window. However, this can be triggered by other calls to
`Figure.set_size_inches` as noted in the fixed issues.

Fixes matplotlib#10083.
Fixes matplotlib#10566.
Fixes matplotlib#16926.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants