Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Wrong figure height after set_size_inches within event handler #10083
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.
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.