使Jupyter笔记本中的单元格输出水平滚动? [英] Make cell output in Jupyter notebook scroll horizontally?

查看:553
本文介绍了使Jupyter笔记本中的单元格输出水平滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的Sympy表达式,我想用它下面的水平滚动条进行打印.在Jupyter中可以这样做吗?我可以切换垂直滚动,但我希望它可以水平滚动.垂直滚动的问题是在我的情况下sympy.pretty_print()的输出严重失真.输出看起来也很丑陋,用户必须不必要地滚动整个输出.

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.

推荐答案

类似于np.set_printoptions(linewidth=some_large_number)和/或np.set_printoptions(threshold=some_large_number)方法的方法可能很有用,但如果Jupyter的输出窗口本身太窄,则无法解决问题.

Something similar to the np.set_printoptions(linewidth=some_large_number) and/or np.set_printoptions(threshold=some_large_number) approach can be useful but doesn't fix the problem if Jupyter's output window is itself too narrow.

我最终得到的最快的解决方案是在笔记本顶部的某处插入以下行:

The quickest solution I ended up with is inserting this line somewhere at the top of your notebook:

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

如果要为所有笔记本电脑更改此设置,则需要弄乱Jupyter的custom.css配置文件,如所讨论的

If you want to change this setting for all of your notebooks, you'll need to mess around with the custom.css config file for Jupyter as discussed here.

我浪费了太多时间弄清楚这一点.希望我能帮助一些人更快地弄清楚!

I wasted too much time figuring this out. Hopefully I can help some of you figure it out quicker!

这篇关于使Jupyter笔记本中的单元格输出水平滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆