FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

set_size_inches doesn't resize window on macosx backend · Issue #15131 · matplotlib/matplotlib · GitHub

Repository navigation

set_size_inches doesn't resize window on macosx backend #15131

Closed

Description

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

Activity

  1. added this to the v3.3.0 milestone on Aug 27, 2019
  2. lukelbd commented on Jan 6, 2020

    Contributor

    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).

  3. jklymak commented on Jan 6, 2020

    Member

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

  4. lukelbd commented on Jan 6, 2020

    Contributor

    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 :)

  5. jklymak commented on Jan 6, 2020

    Member

    .. 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".

  6. lukelbd commented on Jan 6, 2020

    Contributor

    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).

  7. lukelbd commented on Jan 6, 2020

    Contributor

    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.

  8. dopplershift commented on Mar 31, 2020

    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.

  9. dstansby commented on May 5, 2020

    MemberAuthor

    Thanks for the PR/fix @dopplershift !

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL