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.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
RussAbbott
  • 2,660
  • 4
  • 24
  • 37
  • 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](https://stackoverflow.com/q/21176731/190597) to automatically run `%matplotlib inline` whenever IPython notebook is started.) – unutbu May 28 '18 at 02: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? – RussAbbott May 28 '18 at 02:05
  • I'm not quite sure, but I believe the issue here is that there are a number of possible [matplotib backends](https://matplotlib.org/tutorials/introductory/usage.html#backends) available and IPython/Jupyter is not picking the right one / has not been configured to pick the one you desire. See [this question](https://stackoverflow.com/q/43027980/190597) which has links to the docs. – unutbu May 28 '18 at 02:17

0 Answers0