Skip to content

enable figures to be excluded from calls to show() #16377

Closed as not planned
Closed as not planned

Description

@keatonb

Feature request

Calling matplotlib.pyplot.show() displays all active figures. There are times this is not desirable, such as when some figure is still being developed. Of course, show() can be called for specific figures, but perhaps a user doesn't know that an undisplayed figure belongs to a class instance and these all get displayed when they call show() for their own plot.

Example at https://stackoverflow.com/q/59995448/4302578

It would be great if there was some attribute of a figure like figure.show_by_default, figure.implicit_show, or figure.exclude_from_show that could be set to stop these from popping up when plt.show() is called without arguments.

Activity

  1. anntzer commented on Jan 30, 2020

    @anntzer
    Contributor

    I think this is basically a variant on #14024.

  2. keatonb commented on Jan 31, 2020

    @keatonb
    Author

    The behavior I want is achieved, in effect, after the figures I do not want to show have been shown once with a call to show() (i.e., I can still modify them and display them directly by accessing their canvasses, but they don't show up again with later calls to show). Is there a way I can make matplotlib think that show has already been called for specific figures, without having to actually displaying them with show?

  3. ImportanceOfBeingErnest commented on Jan 31, 2020

    @ImportanceOfBeingErnest
    Member

    In principle this is what plt.close(fig) is for. The problem is just that figures that are closed, cannot be reopenend as of now.
    #14024 (+ making sure every figure has a manager(?)) would make that possible though.

    The ideal solution to the problem in the stackoverflow post would probably be not to use pyplot at all. But then it's hard to get the notebook to identify the canvas as something "showable".

  4. ImportanceOfBeingErnest commented on Jan 31, 2020

    @ImportanceOfBeingErnest
    Member

    Btw. you can attach the manager manually, so

    %matplotlib widget
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_nbagg import FigureCanvasNbAgg, FigureManagerNbAgg
    
    class interactiveplot(object):
        def __init__(self, x, y):
    
            self.fig = Figure(figsize=(2,2))
            self.canvas = FigureCanvasNbAgg(self.fig)
            self.canvas.manager = FigureManagerNbAgg(self.canvas, 2)
            self.ax = self.fig.subplots()
            self.plot, = self.ax.plot(x,y)
        def update(self,x,y):
            self.plot.set_data(x,y)
            self.fig.canvas.draw()
        def show(self):
            self.canvas.manager.show()
    

    should work?

  5. keatonb commented on Feb 3, 2020

    @keatonb
    Author

    Your example does work, but I also want to be able to display the plots via their canvasses (using ipympl) without calling show(), since in my actual problem the class I have returns a Box containing both ipywidgets and mpl canvasses.

  6. github-actions commented on Jul 7, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  7. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Aug 7, 2023
  8. tacaswell commented on Aug 7, 2023

    @tacaswell
    Member

    I am comfortable leaving this closed, directly creating the Figure s (with which ever canvsa you want) will create Figures that are unknown to pyplot and hence will not be implicated by plt.show().

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions