谢谢!
如果您不想更改默认设置,只想更改当前笔记本的宽度,可以在单元格中输入以下内容:
from IPython.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
display("text/html", "<style>.container { width:100% !important; }</style>")
。 - Lisodisplay(HTML("<style>.output_result { max-width:100% !important; }</style>"))
以更改其宽度! - onofricamila那个 div.cell
的解决方案在我的 IPython 上并没有实际起作用,不过幸运的是有人提出了一个新的 IPython 的可行解决方案:
创建一个文件 ~/.ipython/profile_default/static/custom/custom.css
(iPython) 或者 ~/.jupyter/custom/custom.css
(Jupyter),并将以下内容添加进去:
.container { width:100% !important; }
然后重新启动iPython/Jupyter笔记本。请注意,这将影响所有笔记本。
~/.jupyter/custom/
。 - Romain为了使其在jupyter(版本4.0.6)中工作,我创建了~/.jupyter/custom/custom.css
文件,其中包含:
/* Make the notebook cells take almost all available width */
.container {
width: 99% !important;
}
/* 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 !important;
}
jupyter --config-dir
,然后在该命令返回的任何位置创建 custom\custom.css
。 - jvd10custom.css
除了上面的代码片段之外还有其他代码吗?另外,Jupyter是如何知道要使用它的? - mLstudent33.jupyter
的隐藏目录以获取配置文件,包括上述自定义内容。上述内容应该是custom.css的唯一内容。有关更多信息,请参见此处:https://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html#config-dir - jvd10是时候开始使用JupyterLab了。
终于,Notebook 迎来了一个非常必要的升级。JupyterLab 默认使用窗口的全部宽度,就像其他完整的本地 IDE 一样。
你所需要做的就是:
pip install jupyterlab
# if you use conda
conda install -c conda-forge jupyterlab
# to run
jupyter lab # instead of jupyter notebook
通常在新安装后,我会修改存储所有视觉样式的主 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 cells,这使我回到了这里并提醒自己。
如果你需要在虚拟环境中安装的Jupyter上进行此操作,你可以在这个子目录下找到css文件
env/lib/python3.6/site-packages/notebook/static/style/stye.min.css
/notebook
。 - mLstudent33from IPython.display import display, HTML
display(HTML("<style>:root { --jp-notebook-max-width: 100% !important; }</style>"))
~/.jupyter/custom/custom.css
中的:root { --jp-notebook-max-width: 100% !important; }
并不起作用:/ ...有什么建议吗?谢谢 - undefined这是我最终使用的代码。它将输入和输出单元格向左右两侧拉伸。请注意,输入/输出编号指示将消失:
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。例如,请查看12步到Navier Stokes课程。
特别地,创建一个包含样式信息的文件
<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()
这将应用所有样式,特别是更改单元格宽度。
@media (min-width: 1140px) {
.container {
width: 1130px;
}
}
.end_space {
height: 800px;
}
对于Chrome用户,我推荐使用Stylebot,它可以让您覆盖任何页面上的CSS,并允许您搜索和安装其他共享自定义CSS。但是,为了我们的目的,我们不需要任何高级主题。打开Stylebot,切换到Edit CSS
。Jupyter会捕获一些按键操作,因此您将无法键入下面的代码。只需复制并粘贴,或使用您的编辑器:
#notebook-container.container {
width: 90%;
}
根据个人喜好更改宽度,我发现90%看起来比100%更好看。但是完全取决于你的审美。
print(...)
输出矩阵或列表,则换行仍然发生在相同位置,因此输出未使用添加的空间。 - Timonp.set_printoptions(linewidth=110)
对我来说有效。 - Timo