本文介绍了如何通过sympy在ipython笔记本中进行漂亮的打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了pprint
,print
,前者只能打印Unicode版本,而后者却不能打印漂亮的图像.
I tried pprint
, print
, the former only prints Unicode version, and the latter doesn't do pretty prints.
from sympy import symbols, Function
import sympy.functions as sym
from sympy import init_printing
init_printing(use_latex=True)
from sympy import pprint
from sympy import Symbol
x = Symbol('x')
# If a cell contains only the following, it will render perfectly.
(pi + x)**2
# However I would like to control what to print in a function,
# so that multiple expressions can be printed from a single notebook cell.
pprint((pi + x)**2)
推荐答案
您需要使用display:
you need to use display:
from IPython.display import display
display(yourobject)
它将选择适当的表示形式(text/LaTex/png ...),在默认情况下,默认情况下会导入最新版本的IPython(6.0+)显示,仍然建议显式导入.
It will choose the appropriate representation (text/LaTex/png...), in recent enough version of IPython (6.0+) display is imported by default, still we recommend to explicitly import it.
这篇关于如何通过sympy在ipython笔记本中进行漂亮的打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!