使 Jupyter Notebook 中的单元格输出水平滚动?

2024-04-30

I have a long Sympy expression that I'd like to get printed with a horizontal scrollbar beneath it. Is it possible to do so in Jupyter? I'm able to toggle vertical scrolling but I want it to be horizontally scrollable instead. The problem with vertical scrolling is that the output of sympy.pretty_print() gets badly distorted in my case. The output also looks ugly and the user has to scroll through the whole output unnecessarily.enter image description here


类似的东西np.set_printoptions(linewidth=some_large_number) and/or np.set_printoptions(threshold=some_large_number)如果 Jupyter 的输出窗口本身太窄,该方法可能很有用,但无法解决问题。

我最终找到的最快的解决方案是将这一行插入笔记本顶部的某个位置:

from IPython.display import display, HTML
display(HTML("<style>pre { white-space: pre !important; }</style>"))

如果您想更改所有笔记本的此设置,则需要修改custom.css讨论的 Jupyter 配置文件here https://stackoverflow.com/a/34742362/3857460.

我浪费了太多时间来解决这个问题。希望我能帮助你们中的一些人更快地弄清楚!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使 Jupyter Notebook 中的单元格输出水平滚动? 的相关文章

随机推荐