【问题标题】:How to not show graphs until plt.show() in jupyter notebook or jupyter_lab如何在 jupyter notebook 或 jupyter_lab 中的 plt.show() 之前不显示图表
【发布时间】:2019-06-26 15:07:03
【问题描述】:

我正在使用 jupyter 和 jupyter lab 来分析数据。

如果显示图表,我想在最后一个单元格中显示所有图表。

但是 jupyter 和 jupyter lab 在设置绘图代码后立即显示图形

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

我想要做的是在不同的单元格上方设置绘图并显示在最后一个单元格中。

【问题讨论】:

标签: python jupyter-notebook jupyter-lab


【解决方案1】:

这是how to reuse plot in a next jupyter 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.

要在以后的单元格中显示该图,您只需再次调用该图:

第二个单元格

fig

这将显示图形

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 2020-09-21
    • 1970-01-01
    • 2014-03-08
    • 2017-05-11
    • 1970-01-01
    相关资源
    最近更新 更多