我用的是ipython Jupyter笔记本。假设我定义了一个函数,它在屏幕上占据了很大的空间。有办法让细胞崩溃吗?
我希望函数保持执行和可调用,但我想隐藏/折叠单元格,以便更好地可视化笔记本。我该怎么做呢?
我用的是ipython Jupyter笔记本。假设我定义了一个函数,它在屏幕上占据了很大的空间。有办法让细胞崩溃吗?
我希望函数保持执行和可调用,但我想隐藏/折叠单元格,以便更好地可视化笔记本。我该怎么做呢?
当前回答
JupyterLab支持细胞折叠。单击左侧的蓝色单元格条将折叠单元格。
其他回答
我有同样的问题,我发现这个扩展有用
pip install aquirdturtle_collapsible_headings
hide_code扩展允许您隐藏单个单元格和/或它们旁边的提示符。安装
pip3 install hide_code
访问https://github.com/kirbs-/hide_code/了解有关此扩展的更多信息。
您可以创建一个单元格,并将以下代码放在其中:
%%html
<style>
div.input {
display:none;
}
</style>
运行此单元格将隐藏所有输入单元格。要显示它们,可以使用菜单清除所有输出。
否则,你可以尝试笔记本扩展如下:
https://github.com/ipython-contrib/IPython-notebook-extensions/wiki/Home_3x
JupyterLab支持细胞折叠。单击左侧的蓝色单元格条将折叠单元格。
还有一个潘岩建议的改进版本。它添加了显示代码单元格的按钮:
%%html
<style id=hide>div.input{display:none;}</style>
<button type="button"
onclick="var myStyle = document.getElementById('hide').sheet;myStyle.insertRule('div.input{display:inherit !important;}', 0);">
Show inputs</button>
或python:
# Run me to hide code cells
from IPython.core.display import display, HTML
display(HTML(r"""<style id=hide>div.input{display:none;}</style><button type="button"onclick="var myStyle = document.getElementById('hide').sheet;myStyle.insertRule('div.input{display:inherit !important;}', 0);">Show inputs</button>"""))