我想在浏览器中增加ipython笔记本的宽度。我有一个高分辨率的屏幕,我想扩大单元格的宽度/大小,以利用这个额外的空间。

谢谢!


编辑/回答:2017年5月

我现在使用jupyterthemes: https://github.com/dunovank/jupyter-themes

还有这命令:

jt -t oceans16 -f roboto -fs 12 -cellw 100%

这设置宽度为100%与一个漂亮的主题。


当前回答

是时候使用jupyterlab了

笔记本电脑终于迎来了迫切需要的升级。默认情况下,Jupyterlab使用窗口的全宽度,就像任何其他成熟的本地IDE一样。

你所要做的就是:

pip install jupyterlab
# if you use conda
conda install -c conda-forge jupyterlab
# to run 
jupyter lab    # instead of jupyter notebook

这是来自blog.Jupyter.org的截图

其他回答

您可以通过从任何单元格调用样式表来设置笔记本的CSS。举个例子,看看Navier Stokes课程的12步。

特别是,创建一个包含

<style>
    div.cell{
        width:100%;
        margin-left:1%;
        margin-right:auto;
    }
</style>

应该能给你一个起点。然而,可能还需要调整例如div.text_cell_render来处理markdown以及代码单元格。

如果该文件是custom.css,则添加包含以下内容的单元格:

from IPython.core.display import HTML
def css_styling():
    styles = open("custom.css", "r").read()
    return HTML(styles)
css_styling()

这将应用所有样式,特别是改变单元格宽度。

div.cell解决方案实际上在我的IPython上不起作用,但幸运的是,有人为新的IPython提出了一个有效的解决方案:

创建一个包含内容的文件~/.ipython/profile_default/static/custom/custom.css (iPython)或~/.jupyter/custom/custom.css (Jupyter)

.container { width:100% !important; }

然后重新启动iPython/Jupyter笔记本。注意,这将影响所有笔记本电脑。

对于Firefox/Chrome用户,实现100%宽度的好方法是使用自定义TamperMonkey脚本。

好处是

在浏览器中配置一次,不需要修改服务器配置。 工作与多个jupyter服务器。 TamperMonkey是可信的、维护的、稳定的。 很多额外的定制是可以通过javascript实现的。

这个脚本为我工作https://gist.githubusercontent.com/mrk-andreev/2a9c2538fad0b687c27e192d5948834f/raw/6aa1148573dc20a22fca126e56e3b03f4abf281b/jpn_tmonkey.js

请注意,如果您使用旧的方法执行此操作,现在将得到一个弃用警告。这使用了较新的子模块命名:

from IPython.display import HTML

HTML("<style>.container { width:100% !important; }</style>")

如果您不想更改默认设置,并且只想更改当前正在使用的笔记本电脑的宽度,可以在单元格中输入以下内容:

from IPython.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))