Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I properly format this equation in the title of my plot? (python 3)

I am trying to add a title with the correct syntax to print the formula for a Gaussian distribution and don't see my mistake. Can someone help me spot it? My attempt is below and produces this result while the formula should look like f(x) = right hand side of this. I am asking for python3, though I think it's the same as LaTeX.

title = "Gaussian Distribution: f(x) = $\\frac{1/\sigma (2\pi)^{frac{1/2}}} \exp( \\frac{(x-\mu)^2 / 2\sigma^2} )"
plt.title(title)

1 Answers

MathText expressions must be enclosed by $ signs.
They must be valid latex commands, i.e. an opening { must have a closing }.
Using raw strings makes escaping unnecessary.

title = r"f(x) =  $\frac{1}{\sigma \sqrt{2\pi}}  e^{\frac{(x-\mu)^2 }{ 2\sigma^2}}$"

enter image description here

like image 158
ImportanceOfBeingErnest Avatar answered Oct 22 '25 03:10

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!