Make cell output in Jupyter notebook scroll horizontally?

六月ゝ 毕业季﹏ 提交于 2019-12-08 16:38:20

问题


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.


回答1:


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>"))

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!




回答2:


On hovering right below

out[]:

in notebook you see "scroll output" . On clicking anywhere in that area you get your output scrollable both horizontally and vertically.



来源:https://stackoverflow.com/questions/48357459/make-cell-output-in-jupyter-notebook-scroll-horizontally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!