Borun Chowdhury
Borun Chowdhury

Reputation: 531

How do I plot an axis object?

I have an axes object that I previously did not plot.

_,ax=plt.subplots(1,1)
ax.plot(range(10))
plt.close()

I now want to plot it. How do I do it? I know it can be done because I pass the ax object to wandb.ai API to plot on their dashboards.

Upvotes: 1

Views: 320

Answers (1)

Mad Physicist
Mad Physicist

Reputation: 114300

Calling plt.close closes the last figure you worked on. Once a figure is closed, you will not be able to plot it.

plt.show will display all open figures no matter where you call it. So as long as you remove the call to close, you can call show later in your code.

The red herring here is that you are able to plot by passing an Axes object to wandb.ai. Closing a figure does not necessarily destroy the underlying data and display metadata: it just destroys its ability to show up in the current GUI. Closing the figure does not prevent a valid Axes object from being passed to the online API wrapper, and serialized data from being sent to the server. It just prevents the enclosing Figure object from being displayed locally.

Upvotes: 1

Related Questions