如何在浏览器中增加Jupyter / ipython笔记本的单元格宽度?

这篇博客分享了如何在高分辨率屏幕上增加Jupyter Notebook的单元格宽度,包括使用jupyterthemes、自定义CSS、修改配置文件以及使用Stylish浏览器插件等方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:How do I increase the cell width of the Jupyter/ipython notebook in my browser?

I would like to increase the width of the ipython notebook in my browser. 我想在浏览器中增加ipython笔记本的宽度。 I have a high-resolution screen, and I would like to expand the cell width/size to make use of this extra space. 我有一个高分辨率的屏幕,我想扩展单元格的宽度/大小以利用这个额外的空间。

Thanks! 谢谢!


edit: 5/2017 编辑:5/2017

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

and this command: 和此命令:

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

which sets the width to 100% with a nice theme. 可以将宽度设置为100%,并且主题很好。


#1楼

参考:https://stackoom.com/question/1UBmD/如何在浏览器中增加Jupyter-ipython笔记本的单元格宽度


#2楼

You can set the CSS of a notebook by calling a stylesheet from any cell. 您可以通过从任何单元格调用样式表来设置笔记本的CSS。 As an example, take a look at the 12 Steps to Navier Stokes course . 作为示例,请看Navier Stokes课程12个步骤

In particular, creating a file containing 特别是,创建一个包含

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

should give you a starting point. 应该给你一个起点。 However, it may be necessary to also adjust eg div.text_cell_render to deal with markdown as well as code cells. 但是,可能还需要调整例如div.text_cell_render来处理降价和代码单元。

If that file is custom.css then add a cell containing: 如果该文件是custom.css则添加一个包含以下内容的单元格:

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

This will apply all the stylings, and, in particular, change the cell width. 这将应用所有样式,尤其是更改像元宽度。


#3楼

That div.cell solution didn't actually work on my IPython, however luckily someone suggested a working solution for new IPythons: div.cell解决方案实际上不适用于我的IPython,但是幸运的是有人提出了适用于新IPython的可行解决方案:

Create a file ~/.ipython/profile_default/static/custom/custom.css (iPython) or ~/.jupyter/custom/custom.css (Jupyter) with content 创建一个~/.ipython/profile_default/static/custom/custom.css (iPython)或~/.jupyter/custom/custom.css (Jupyter)的文件

.container { width:100% !important; }

Then restart iPython/Jupyter notebooks. 然后重新启动iPython / Jupyter笔记本。 Note that this will affect all notebooks. 请注意,这将影响所有笔记本电脑。


#4楼

If you don't want to change your default settings, and you only want to change the width of the current notebook you're working on, you can enter the following into a cell: 如果您不想更改默认设置,而只想更改正在使用的当前笔记本的宽度,则可以在单元格中输入以下内容:

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

#5楼

To get this to work with jupyter (version 4.0.6) I created ~/.jupyter/custom/custom.css containing: 为了使它与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;
}

#6楼

(As of 2018, I would advise trying out JupyterHub/JupyterLab. It uses the full width of the monitor. If this is not an option, maybe since you are using one of the cloud-based Jupyter-as-a-service providers, keep reading) (从2018年开始,我建议尝试使用JupyterHub / JupyterLab。它使用监视器的整个宽度。如果这不是一种选择,则可能是因为您使用的是基于云的Jupyter即服务提供商,继续阅读)

(Stylish is accused of stealing user data, I have moved on to using Stylus plugin instead) (时尚被指控窃取用户数据,我已改为使用Stylus插件)

I recommend using Stylish Browser Plugin . 我建议使用时尚浏览器插件 This way you can override css for all notebooks, without adding any code to notebooks. 这样,您可以覆盖所有笔记本的css,而无需在笔记本中添加任何代码。 We don't like to change configuration in .ipython/profile_default, since we are running a shared Jupyter server for the whole team and width is a user preference. 我们不喜欢在.ipython / profile_default中更改配置,因为我们正在为整个团队运行共享的Jupyter服务器,并且宽度是用户的首选项。

I made a style specifically for vertically-oriented high-res screens, that makes cells wider and adds a bit of empty-space in the bottom, so you can position the last cell in the centre of the screen. 我为垂直方向的高分辨率屏幕专门设计了一种样式,该样式使单元格变宽,并在底部添加了一些空白空间,因此您可以将最后一个单元格放置在屏幕的中央。 https://userstyles.org/styles/131230/jupyter-wide You can, of course, modify my css to your liking, if you have a different layout, or you don't want extra empty-space in the end. https://userstyles.org/styles/131230/jupyter-wide当然,如果您使用其他布局,或者您不希望最后有多余的空白,您当然可以根据自己的喜好修改我的CSS。

Last but not least, Stylish is a great tool to have in your toolset, since you can easily customise other sites/tools to your liking (eg Jira, Podio, Slack, etc.) 最后但并非最不重要的一点是,Stylish是包含在工具集中的出色工具,因为您可以根据自己的喜好轻松自定义其他站点/工具(例如Jira,Podio,Slack等)。

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

.end_space {
  height: 800px;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值