强制Sympy在MathJax Jupyter中打印数学。

问题描述 投票:0回答:1

我是用VSCode和Jupyter在Sympy上工作。正常情况下,它用MathJax格式打印数学公式,sympy文档中说。

在IPython笔记本中,它将使用MathJax来渲染LATEX。

MathJax输出。

enter image description here

但是,当我安装了matplotlib后,它就会自动用matplotlib打印成图像。

Matplotlib输出。

enter image description here

我必须安装matplotlib才能绘制结果。有什么办法可以强制sympy以MathJax格式打印数学?我使用了

init_printing(use_latex=True)

这没有工作。有什么好办法吗?

matplotlib visual-studio-code jupyter-notebook sympy mathjax
1个回答
1
投票

试试这段代码。

from IPython.display import Math, display
import sympy as sy

x = sy.symbols('x')
expression = sy.sin(x)

display(Math('f(x) = ' + sy.latex(expression)))

或者,针对你的情况,使用 LaTeX 格式。

display(Math('\\left[ \\frac{3\\mu_2^2+2\\sigma_2^2\\log(2)}{2\\mu_2} \\right]'))

这就是结果。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.