How to clear graphs sequentially in IPython Notebook?

for i in range(3): print("Info ",i) plt.figure() plt.plot(np.arange(10)*(i+1)) 

In the IPython notebook, three informational messages will be printed first, and then build three numbers.

Which command can I use to ensure consistent display of prints and graphs? That is, print "Info 0", a graph of "Figure 0", type "Info 1", a graph of "Figure 1", etc.

This is a simple example with blue bones. In my case, this is much more complicated, and it is important to get the behavior right.

+5
source share
2 answers

Just add plt.show() to the desired location.

 %matplotlib inline import matplotlib.pyplot as plt import numpy as np for i in range(3): print "Info ",i plt.plot(np.arange(10)*(i+1)) plt.show() 
+4
source

IPython first evaluates all the code in your cell. When this is done, open numbers will be displayed in the output area.

If this is not what you want, you can display your numbers manually. However, you must definitely close all newly created curly objects before completing the cell evaluation.

This is a short example:

 %matplotlib inline import matplotlib.pyplot as plt import numpy as np from IPython.display import display for i in range(3): print("Info ",i) fig, ax = plt.subplots() ax.plot(np.arange(10)*(i+1)) display(fig) plt.close() 
0
source

Source: https://habr.com/ru/post/1237416/


All Articles