-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Cleanup _pylab_helpers. #13581
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
Cleanup _pylab_helpers. #13581
Conversation
"""Destroy figure *fig*.""" | ||
canvas = getattr(fig, "canvas", None) | ||
manager = getattr(canvas, "manager", None) | ||
num = getattr(manager, "num", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this always equivalent, since it seems to be working in reverse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This basically gets fig.canvas.manager.num
with the provision that each of these can be None. If this num is not registered in the figs
dict, destroy
will catch that as it first checks cls.has_fignum(num)
.
It's true that this may cause problems if two managers share the same num, but then the num->manager mapping is already invalid (set_active
will already have overwritten the entry in the dict) so I'm not too worried about that.
lib/matplotlib/_pylab_helpers.py
Outdated
*_activeQue*: | ||
list of *managers*, with active one at the end | ||
|
||
Singleton to handle a set of "numbered" figures and managers, and keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the whole docstring a bit unclear. It seems to assume prior knowledge on figures, figure managers and their relation. Would this be a more complete description?
Singleton to maintain the relation between figures and their managers, and
keep track of and "active" figure and manager.
When created via pyplot, a figure is associated with its own figure
manager, that handles the interaction between the figure and the backend.
This association is established via a unique identifier, called
*figure number* or *manager number*. While figure numbers are often actual
numbers, they can actually be any hashable value. The number is attached
to the figure via the `.Figure.number` attribute; and it's mapped to a
manager in the `.Gcf.figs` dictionary.
This class is never instantiated; it consists of an `OrderedDict` mapping
figure/manager numbers to managers, and a set of class methods that
manipulate this `OrderedDict`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the number is an attribute of the manager (which is itself an attribute of the canvas), but other than that, looks good. Will incorporate a slightly edited version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed edited version. (Note that the identifier does not create the association, it's just used for bookkeeping.)
_activeQue + figs can be combined into a single OrderedDict.
Two approvals... |
This is a partial revert of a small part of matplotlib#13581. Fixes matplotlib#18163.
This is a partial revert of a small part of matplotlib#13581. Fixes matplotlib#18163.
_activeQue + figs can be combined into a single OrderedDict.
PR Summary
PR Checklist