0

I have a simple question regarding matplotlib figure objects.

I have the following code in a function library named gauss that returns a figure:

def plot_3d(X,Y,Z):
    fig1 = plt.figure(1)
    ax1 = Axes3D(fig1)
    surf = ax1.plot_surface(X,Y,Z,cmap=cm.coolwarm)
    fig1.colorbar(surf,shrink=0.5,aspect=5)
    ax1.set_xlabel('x')
    ax1.set_ylabel('y')
    ax1.set_zlabel('f(x,y)')
    return fig1

In the interpreter, I run the code with a given X,Y,Z

fig = gauss.plot_3d(X,Y,Z)

And the code calls the object. But once I close the object, how can I call it again?

Something along the lines of

plt.show(fig)

?

3
  • What is wrong with plt.show(fig)? That works fine for me. Commented Jun 26, 2014 at 18:36
  • I'm using Spyder with the interpreter inside and it doesn't seem to work. Commented Jun 26, 2014 at 18:51
  • 1
    I'm pretty sure that once you close a Figure instance through a GUI or otherwise, it's gone. Commented Jun 26, 2014 at 23:08

1 Answer 1

2

The arg on show does not do what you think it does. show eats *args, **kwargs, but it really just gets passed to a bool if it should block or not.

Once you have closed a figure it get deleted from pyplot's registry of active figures. If you still have a reference to the figure you can try to show it again by reaching into the internals of the figure and poking at the figure's canvas's manager's window.

ex (for the qt backend):

fig, ax = plt.subplots()

then close the window, and then

fig.canvas.manager.window.show()

should make it pop back up.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.