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

谢谢!


编辑/回答:2017年5月

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

还有这命令:

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

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


当前回答

您可以通过从任何单元格调用样式表来设置笔记本的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()

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

其他回答

是时候使用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()

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

我对@jvd10的解决方案做了一些修改。“!important'似乎太强了,当TOC侧栏显示时,容器不能很好地适应。我删除了它,并添加了“min-width”来限制最小宽度。

这是我的。juyputer/custom/custom.css:

/* Make the notebook cells take almost all available width and limit minimal width to 1110px */
.container {
    width: 99%;
    min-width: 1110px;
}   

/* Prevent the edit cell highlight box from getting clipped;
 * important so that it also works when cell is in edit mode*/
div.cell.selected {
    border-left-width: 1px;
}

这是我最终使用的代码。它将输入和输出单元格向左和向右拉伸。注意,输入/输出数字指示将消失:

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

我通常在新安装后修改存储所有视觉样式的主css文件。我使用Miniconda,但位置与其他C:\Miniconda3\Lib\site-packages\notebook\static\style\style.min.css类似

对于某些屏幕,这些分辨率是不同的,并且大于1。为了安全起见,我把所有屏幕都改成了98%,所以如果我断开了笔记本电脑的外部屏幕,我的屏幕宽度仍然是98%。

然后用98%的屏幕宽度替换1140px。

@media (min-width: 1200px) {
  .container {
    width: 1140px;
  }
}

后编辑

@media (min-width: 1200px) {
  .container {
    width: 98%;
  }
}

保存并重新启动你的笔记本


更新

最近不得不拓宽Jupyter细胞上的一个环境,它是安装,这导致我回到这里,提醒自己。

如果你需要在虚拟环境中安装jupyter。你可以在这个子目录下找到css文件

env/lib/python3.6/site-packages/notebook/static/style/stye.min.css