I'm trying to make a notebook where the data produced by a long for loop is put in a graph point by point. However, when using %matplotlib notebook
and fig.canvas.draw()
the graph is tiny up until the cell finishes running. (In fact, I've got many of those graphs and they are even tinyer when using more subplots.)
Here my code reproducing the behaviour in a jupyter notebook, at least on OS X with (latest) jupyter-core 4.3.0 and (latest) matplotlib 2.0.2.
%matplotlib notebook
import time
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
for _ in range(5):
ax.plot([1,2,3], [1,2,3])
fig.canvas.draw()
time.sleep(1)
During the cell execution I get this plot
And when the cell finishes execution (after 5 seconds) I get this
I would like to get the larger image even during cell execution. What am I doing wrong?
Next, to increase the size of the plot in the jupyter notebook use plt. rcParams[“figure. figsize”] method and set width and height of the plot.
Basically, the plt is a common alias of matplotlib. pyplot used by most people. When we plot something using plt such as plt. line(...) , we implicitly created a Figure instance and an Axes inside the Figure object.
Plotting from an IPython shell draw() . Using plt. show() in Matplotlib mode is not required.
As proposed by ImportanceOfBeingErnest, one solution is to put the figure creation in its own cell.
[1] %matplotlib notebook
import time
import matplotlib.pyplot as plt
[2] fig, ax = plt.subplots(1, 1)
[3] for _ in range(5):
ax.plot([1,2,3], [1,2,3])
fig.canvas.draw()
time.sleep(1)
Edit: This solutions does not work if you run all cells at once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With