Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not show graphs until plt.show() in jupyter notebook or jupyter_lab

I am using jupyter and jupyter lab to analyze data.

In case of showing graph, I want to show all of graph in the last cell.

But jupyter and jupyter lab show graph right after setting plot code like

plt.scatter(regdata[0],regdata[1])

What I want to do is setting plots in above different cells and showing in the last cell.

like image 898
hiro Avatar asked Sep 03 '25 02:09

hiro


1 Answers

This is a duplicate of how to reuse plot in a next jupyter cell.

To summarise, you can just call the figure again in a later cell.

First cell

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

x = np.arange(0, 10)
y = x**2

fig, ax = plt.subplots()
ax.plot(x, y)
plt.close() # close figure to stop it showing in this cell.

To display this figure in a later cell you can just call the figure again:

Second cell

fig

This will display the figure

like image 108
FChm Avatar answered Sep 04 '25 14:09

FChm