简体   繁体   中英

Calling matplotlib plot objects to show on Screen

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)

?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM