Skip to content

set_size_inches doesn't resize window on macosx backend #15131

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
dstansby opened this issue Aug 26, 2019 · 8 comments · Fixed by #16992
Closed

set_size_inches doesn't resize window on macosx backend #15131

dstansby opened this issue Aug 26, 2019 · 8 comments · Fixed by #16992
Milestone

Comments

@dstansby
Copy link
Member

Using set_size_inches() correct resizes the figure canvas, but doesn't resize the window with the macosx backend:

import matplotlib
matplotlib.use('macosx')
import matplotlib.pyplot as plt

fig1, ax = plt.subplots()
fig1.set_size_inches(2, 2)
plt.show()

results in
Screenshot 2019-08-26 at 18 06 29

@tacaswell tacaswell added this to the v3.3.0 milestone Aug 27, 2019
@lukelbd
Copy link
Contributor

lukelbd commented Jan 6, 2020

Hopefully this can be fixed soon. This issue prevents me from performing automatic figure resizing in proplot when the MacOSX backend is enabled (on macOS Catalina).

@jklymak
Copy link
Member

jklymak commented Jan 6, 2020

Is this a regression, or did it always do this?

@lukelbd
Copy link
Contributor

lukelbd commented Jan 6, 2020

Not sure. Looks like the MacOSX backend dates back very far but I couldn't find any other issues. I wouldn't be surprised if this is restricted to the latest macOS versions (Catalina, and IIRC this was also an issue for me on Mojave). Or perhaps very few people resize their figures in-place :)

@jklymak
Copy link
Member

jklymak commented Jan 6, 2020

.. I have it behaving this way back to at least 2.1.0 on Catalina. Someone who needs this to work will need to dig into it to see what the problem is. Given that most of the devs use Qt5 or webAgg, and this has been around for a few years, I wouldn't count on this to be fixed "soon".

@lukelbd
Copy link
Contributor

lukelbd commented Jan 6, 2020

Sorry if that came off wrong, just wanted to generate some discussion / hopefully get the attention of someone more experienced than me. I'll definitely dig around if I get the chance (I also use Qt5 but have been trying to make my auto-figure resizing algorithm more robust).

@lukelbd
Copy link
Contributor

lukelbd commented Jan 6, 2020

The likely culprit is that Figure.set_size_inches calls the figure manager resize method to "push" the resize to the backend, but FigureManagerMac does not implement a resize method:

class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
"""
Wrap everything up into a window for the pylab interface
"""
def __init__(self, canvas, num):
FigureManagerBase.__init__(self, canvas, num)
title = "Figure %d" % num
_macosx.FigureManager.__init__(self, canvas, title)
if rcParams['toolbar'] == 'toolbar2':
self.toolbar = NavigationToolbar2Mac(canvas)
else:
self.toolbar = None
if self.toolbar is not None:
self.toolbar.update()
if matplotlib.is_interactive():
self.show()
self.canvas.draw_idle()
def close(self):
Gcf.destroy(self.num)

So just the empty base method gets called. It also seems that _macosx.FigureManager (inherited by FigureManagerMac) does not have a resize method (see _macosx.m). I tried to implement my own resize method by accessing the "window" like in backend_qt5.py

def resize(self, width, height):
# these are Qt methods so they return sizes in 'virtual' pixels
# so we do not need to worry about dpi scaling here.
extra_width = self.window.width() - self.canvas.width()
extra_height = self.window.height() - self.canvas.height()
self.canvas.resize(width, height)
self.window.resize(width + extra_width, height + extra_height)

but there does not seem to be any sort of "window" object on FigureManagerMac. I also tried simply calling FigureCanvasMac.resize from FigureManagerMac.resize but seems to really mess up the figure display.

Not sure where to go from here; hopefully this helps someone else.

@dopplershift
Copy link
Contributor

I'm making some headway on this, along with a variety of other clean-ups for the macosx backend. It's complicated by the fact that the Figure windows on the Mac backend aren't using any kind of layout--it's hand-coded widget placement.

@dstansby
Copy link
Member Author

dstansby commented May 5, 2020

Thanks for the PR/fix @dopplershift !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants