我想在浏览器中增加ipython笔记本的宽度。我有一个高分辨率的屏幕,我想扩大单元格的宽度/大小,以利用这个额外的空间。
谢谢!
编辑/回答:2017年5月
我现在使用jupyterthemes: https://github.com/dunovank/jupyter-themes
还有这命令:
jt -t oceans16 -f roboto -fs 12 -cellw 100%
这设置宽度为100%与一个漂亮的主题。
我想在浏览器中增加ipython笔记本的宽度。我有一个高分辨率的屏幕,我想扩大单元格的宽度/大小,以利用这个额外的空间。
谢谢!
编辑/回答:2017年5月
我现在使用jupyterthemes: https://github.com/dunovank/jupyter-themes
还有这命令:
jt -t oceans16 -f roboto -fs 12 -cellw 100%
这设置宽度为100%与一个漂亮的主题。
当前回答
这是我最终使用的代码。它将输入和输出单元格向左和向右拉伸。注意,输入/输出数字指示将消失:
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>"))
其他回答
我尝试了所有的方法,没有什么对我有用,我最终使用如下HTML显示我的数据帧
from IPython.display import HTML
HTML (pd.to_html())
对于Firefox/Chrome用户,实现100%宽度的好方法是使用自定义TamperMonkey脚本。
好处是
在浏览器中配置一次,不需要修改服务器配置。 工作与多个jupyter服务器。 TamperMonkey是可信的、维护的、稳定的。 很多额外的定制是可以通过javascript实现的。
这个脚本为我工作https://gist.githubusercontent.com/mrk-andreev/2a9c2538fad0b687c27e192d5948834f/raw/6aa1148573dc20a22fca126e56e3b03f4abf281b/jpn_tmonkey.js
添加到@jdv10和@gerenuk的回答中
最好的选择是添加和调整custom.css文件。下面是我 分享我的CSS文件内容,我用来挤出最大 朱庇特笔记本的屏幕区域。
由于它的目标是呈现页面的普通CSS代码,因此它应该适用于所有类型的CSS代码 用于在笔记本电脑上编码的语言。
/* Notebook styling */ body, p, div.rendered_html { color: #93a1a1; font-family: 'PT Serif', Georgia, Times, 'Times New Roman', serif; font-size: 11pt; } body { background-color: #eee8d5 !important; } /* the following controls aspects which are around the cells */ #notebook { background-color: #073642 !important; box-shadow: inset 20px 36px 20px -35px black !important; margin: 1px !important; padding: 1px !important; } #notebook-container { padding: 2px !important; } /* Make the notebook cells take almost all available width */ .container { width:99.5% !important; /*margin:.5% !important;*/ /*color: #93a1a1 !important;*/ color: black !important; background-color: lightblue !important; } /* Cell output */ .rendered_html pre, .rendered_html code { color: inherit !important; background-color: inherit !important; } .rendered_html table, .rendered_html td, .rendered_html th { border: 1px solid #586e75 !important; } div.cell { width:100% !important; margin: 5px !important; /* margin-left:2px !important; */ /* margin-right:2px !important; */ padding: 2px !important; /* the following overrides the background color of the input area */ /* background-color: yellow !important; */ /* border-color: black !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: 5px !important; border-right-width: 1px !important; border-top-width: 2px !important; border-bottom-width: 2px !important; border-color: red !important; } /*this is for the area to the left of the editor or input area*/ div.run_this_cell { width: auto !important; color: green !important; padding: 0 !important; padding-top: 5px !important; padding-left: 5px !important; font-weight: bold !important; font: 2em sans-serif; } div.input_area { border-color: green !important; background-color: #ffffdd !important; } .prompt { line-height: 1em !important; } div.prompt { min-width: auto; background-color: white; } div.input_prompt { color: #268bd2 !important; color: #000000 !important; font-weight: bold !important; border: 1px solid #ff9900 !important; background-color: greenyellow; padding-right: 0px !important; text-align: center !important; width: auto !important; font-size: 10px !important; } div.output_area { color: #000000 !important; background-color: #e2e2ff !important; font-size: 0.9em !important; } /* Syntax highlighting */ .cm-s-ipython span.cm-comment { /*color: #6c71c4 !important;*/ color: midnightblue !important; color: rgb(100, 100, 170) !important; font-style: italic !important; } .cm-s-ipython span.cm-string { color: rgb(100, 20, 29) !important; }
请注意,如果您使用旧的方法执行此操作,现在将得到一个弃用警告。这使用了较新的子模块命名:
from IPython.display import HTML
HTML("<style>.container { width:100% !important; }</style>")
您可以通过从任何单元格调用样式表来设置笔记本的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()
这将应用所有样式,特别是改变单元格宽度。