我想要在浏览器中增加IPython笔记本的宽度。我的屏幕分辨率很高,我希望扩大单元格的宽度/大小以利用这个额外的空间。
谢谢!
谢谢!
from IPython.display import HTML
HTML("<style>.container { width:100% !important; }</style>")
我对 @jvd10 的解决方案进行了一些修改。 '!important' 似乎太强了,当 TOC 侧边栏显示时容器不适应。我将其删除并添加了 'min-width' 以限制最小宽度。
这是我的 .jupyter/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.display import HTML
HTML (pd.to_html())
通过 @jdv10 和 @gerenuk 的答案进行补充
最佳选择是添加和调整custom.css文件。下面我分享了我的CSS文件内容,我用它来在Jupyter Notebook中获得最大的屏幕显示区域。
由于它针对渲染页面的原始CSS代码,所以应该适用于Notebook上使用的所有编程语言。
/* 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;
}
对于Firefox/Chrome用户,实现100%宽度的好方法是使用自定义TamperMonkey脚本。
其好处为:
print(...)
输出矩阵或列表,则换行仍然发生在相同位置,因此输出未使用添加的空间。 - Timonp.set_printoptions(linewidth=110)
对我来说有效。 - Timo