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

549
我想要在浏览器中增加IPython笔记本的宽度。我的屏幕分辨率很高,我希望扩大单元格的宽度/大小以利用这个额外的空间。
谢谢!

有没有一种方法可以将新的宽度应用于输出格式?如果我使用 print(...) 输出矩阵或列表,则换行仍然发生在相同位置,因此输出未使用添加的空间。 - Timo
1
尝试使用 np.set_printoptions(250) - vgoklani
3
谢谢!np.set_printoptions(linewidth=110) 对我来说有效。 - Timo
1
@vgoklani 抱歉,但是“np”?那来自哪里? - Brandt
1
@Brandt 导入 numpy as np - vgoklani
15个回答

3
请注意,如果您按旧的方法操作,现在会收到废弃警告。这里使用了更新的子模块命名方式:
from IPython.display import HTML

HTML("<style>.container { width:100% !important; }</style>")

这段代码仅适用于当前笔记本电脑。如何使其适用于所有笔记本电脑? - Sameh

3

我对 @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;
}

1
我尝试了很多方法,但都没能解决问题。最终,我使用以下方式将我的数据框显示为HTML:
from IPython.display import HTML    
HTML (pd.to_html())

0

通过 @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;
}


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接