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

Simplify get_current_fig_manager().#14085

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

Merged

Conversation

anntzer
Copy link
Contributor

It's longer to type(!) than its actual implementation
(gcf().canvas.manager), and mixes the pyplot and the OO-interfaces.

Also makeplt.subplot_tool work even for non-pyplot-managed figures
-- there's no reason not to, it's just that such figures cannot be made
the "current" pyplot figure.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzeranntzer added this to thev3.2.0 milestoneApr 29, 2019
timhoffm
timhoffm previously approved these changesApr 29, 2019
Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

get_current_figure_manager() is definitively nothing that should be in the user-facing pyplot API.

Not sure is should stay as a private function or maybe as a method ofFigure. The deep nestinggcf().canvas.manager feels like there's a proper interface layer missing, but I'm not enough into the manager business to judge that.

@anntzer
Copy link
ContributorAuthor

I think the number of cases where a end user needs to access a manager is rare enough that being one additional layer deep is not something to worry about (basically, it's (mostly) only relevant when they're using pyplot to create the figures, but then still want to do stuff with the underlying toolkit widget...).

@timhoffm
Copy link
Member

I was more thinking along the lines: If people use the high-level pyplot API, the shouldn't have to do anything with managers. That mentioned additional layer would more be for experts and for having an internal clean structure.

@tacaswell
Copy link
Member

Accessing the manager can be very useful for setting custom window titles after the fact (which in turn controls how they show up in the task bar).

@anntzer
Copy link
ContributorAuthor

Fair enough, however the point that gcf().canvas.manager is shorter to type and avoids adding API layers for the sake of it remains :)

@timhoffm
Copy link
Member

I have still no clear view what a figure manager does and how the relations betweenFigure,Canvas andFigureManager are. Is this stuff documented somewhere? From what I found in the code, there's one of each for a figure.

  • Figure andCanvas reference each other mutually,
  • LikewiseCanvas andFigureManager reference each other mutually,
  • FigureManager andFigure do not reference each other, butFigureManager.num == Figure.number.

Attempt do define what the classes are for:
Figure is the logic representation of the figure.
Canvas is the technical drawing area and defines the interface between the Figure and the actual backends.
FigureManager - well I have no clear idea. The docstring just says "Helper class for pyplot mode, wraps everything up into a neat bundle", which is not very informative. It seems to be a logic interface to the window used to display a figure on the screen. Would this class be better described asFigureWindow?

Depending on what the manager is actually meant for, it makes sense or not to keep it accessible directly through pyplot. I could also imagine that it makes sense to access the manager through theFigure.

@timhoffmtimhoffm dismissed theirstale reviewApril 30, 2019 10:45

Withdrawing my approval for now as I've realized I don't really understand this stuff.

@anntzer
Copy link
ContributorAuthor

Very briefly, the FigureManager is what holds onto the native qt/gtk/wx/tk window that pyplot sets up to hold the canvas.

@ImportanceOfBeingErnestImportanceOfBeingErnest changed the titleDeprecate get_current_figure_manager().Deprecate get_current_fig_manager().Apr 30, 2019
@ImportanceOfBeingErnest
Copy link
Member

According to stackoverflow Q&As the main/most popular use case ofplt.get_current_fig_manager() is to set the figure window's position or -size, or raise it to the top like

matplotlib.use(<backend>) ...plt.get_current_fig_manager().<backend-dependent way of setting window property>

Answers of this type have an accumulated number of some >50 votes. This seems like a clear sign that there is a lot of code in the wild that would suffer from the deprecation.

In that sense, what is the benefit of removing it?

@anntzer
Copy link
ContributorAuthor

anntzer commentedApr 30, 2019
edited
Loading

If you're already doing something backend dependent, you should just dofig.canvas.<whatever> (canvas is a native widget; you can access the parent window with e.g. canvas.parent() or whatnot (depending on the backend)).
The advantage is that that'll work even if you later move away from pyplot... in my view, the manager is a pretty artificial intermediate layer here.

@tacaswell
Copy link
Member

I am 👍 on the internal changes, 👎 on deprecating it (there is no maintenance burden on it and as@ImportanceOfBeingErnest there would be a real user-cost to this change), 👍 for changing the docstring to saying "use this other thing instead".

@timhoffm In most (all?) cases theCanvas sub-class in the backend is multiply inherited from the base 'Widget' class of the GUI toolkit andjust provides a way to paint the rendered figure to the screen. The manager classes take care of embedding that widget into a window, adding the toolbar, and any GUI specific set up details.

The work in#8777 /#4143 was on attempt at sorting this out.

@timhoffm
Copy link
Member

In the context of what I've understood so far, I'm in favor of leavingget_current_fig_manager() for now.

Even though the name is not great, this is the way to access the backend-specific window etc. In contrast, I seegcf().canvas.manager as an implementation detail. In general, why should a canvas know about it's containing window? If anything, I would expect something likegcf().get_manager() since theFigure is the logic representation. From there, you can either get to the drawing surfacecanvas or to the containing window. Since pyplot is a flat API, it's ok to have a top-level function for this.

@anntzeranntzerforce-pushed theget_current_figure_manager branch from86fe348 tod496e77CompareApril 30, 2019 22:34
Also make ``plt.subplot_tool`` work even for non-pyplot-managed figures-- there's no reason not to, it's just that such figures cannot be madethe "current" pyplot figure.
@anntzeranntzerforce-pushed theget_current_figure_manager branch fromd496e77 toe615fe5CompareApril 30, 2019 22:35
@anntzer
Copy link
ContributorAuthor

To move this forward, I reverted the deprecation and just put in the simpler implementation and docstring.

@timhoffmtimhoffm merged commita84b905 intomatplotlib:masterMay 1, 2019
@timhoffmtimhoffm changed the titleDeprecate get_current_fig_manager().Simplify get_current_fig_manager().May 1, 2019
@anntzeranntzer deleted the get_current_figure_manager branchMay 1, 2019 09:41
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.2.0
Development

Successfully merging this pull request may close these issues.

4 participants
@anntzer@timhoffm@tacaswell@ImportanceOfBeingErnest

[8]ページ先頭

©2009-2025 Movatter.jp