ipap
ipap

Reputation: 311

Programmatically Stop Interaction for specific Figure in Jupyter notebook

In case there is no need for interaction for a specific matplotlib figure in a Jupyter notebook, how to prevent that programmatically?

Manually that can be done by pressing Ctrl-w or clicking the "Stop Interaction" button. I am looking for the API access to the same operation.

Reasons:

Upvotes: 13

Views: 5014

Answers (3)

msabr
msabr

Reputation: 1

You can stop interaction using : plt.ioff()

at the end of the plot.

Upvotes: 0

FJDU
FJDU

Reputation: 1473

The following seems to work, though this is not ideal.

In cell 1

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot([0,1])

In cell 2

plt.close(fig)

Upvotes: 1

Mike Müller
Mike Müller

Reputation: 85442

You can switch between notebook mode with interactivity and inline mode without such interactivity with:

%matplotlib inline

and

%matplotlib notebook

You can do this programmatically in the notebook with:

get_ipython().magic('matplotlib notebook')

or:

get_ipython().magic('matplotlib inline')

Upvotes: 7

Related Questions