3

I am trying to make a plot using matplotlib in ipython notebook.

import matplotlib.pyplot as plt
plt.plot(range(10))
plt.show()

I get the desired plot, but when I try to close it, it hangs. I then have to force quit it, and restart the kernel.

If I run the same code from terminal, I can safely close the plot. The error is when using ipython notebook.

I am on OS X El Capitan (10.11.2), python 2.7. The issue began after updating to El Capitan.

Thanks in advance.

1 Answer 1

1

When your work in a notebook, it is better to display the plots inline. Turn on the inline mode:

In: [1] %matplotlib inline

Now, plot without the plt.show():

In: [2]import matplotlib.pyplot as plt
In: [3]plt.plot(range(10))

The plot should appear right in the notebook.

For interactive plots in the notebook use mpld3. Just add these lines to your notebook:

import mpld3
mpld3.enable_notebook()
Sign up to request clarification or add additional context in comments.

2 Comments

But then I lose the interactivity, I might need to zoom and so on.
@user104493 Not necessarily. See the addition to my answer.

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.