Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Print formula in plot

Sympy returns a print of an expression in Jupyter in mathematical notation. E.g.:

from sympy import symbols
from sympy.plotting import plot

x = symbols("x")

2 + 3 * x**2

will print: enter image description here

However, I can’t include this in a plot title. If I run

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

exp = 2 + 3 * x**2
plot(exp, title=exp)

it will print the expression in the Python notation: 2 + 3 * x**2

Is there any way to get the mathematical notation shown in the plot?

>Solution :

You could do it that way

from sympy import symbols, latex
from sympy.plotting import plot

x = symbols("x")
exp = 2 + 3 * x**2
plot(exp, title='$'+latex(exp)+'$')

latex write the expression as a latex formula. And you need to enclose latex formula with $ so that sympy doesn’t treat the title as raw text.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading