2

I'm running this in the current version of Jupyter.

One of my cells contains the following.

import matplotlib.pyplot as plt

def main():  
    a_list = list(range(20))
    plt.plot(a_list)  
    plt.show()

main()    

When I run kernel > Restart & Run All the only output I get is a plot figure: <matplotlib.figure.Figure at 0x1bd35aa7a20> .

When I run the cell directly with the Run button, I get the expected plot.

When I move main() to its own cell and then run kernel > Restart & Run All I get the expected plot.

I would appreciate help in understanding what's going on.

3
  • If you place %matplotlib inline at the beginning of your notebook and then run kernel > Restart & Run All, do you get the expected plot? (If so, then here is a way to automatically run %matplotlib inline whenever IPython notebook is started.) Commented May 28, 2018 at 2:00
  • Yes, adding %matplotlib inline lets the initial example work as expected. But still, what's going on? Why is that necessary (sometimes)? And how would someone know to do that? Commented May 28, 2018 at 2:05
  • I'm not quite sure, but I believe the issue here is that there are a number of possible matplotib backends available and IPython/Jupyter is not picking the right one / has not been configured to pick the one you desire. See this question which has links to the docs. Commented May 28, 2018 at 2:17

0

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.