I'm using matplotlib to produce some graphics, and I'm using latex for the legends.
More specifically, I'm trying to use something like this:
loglog(x,x, '-r',label='$ \alpha $')
legend()
show()
However, this code does not present a legend on the figure, and gets error after I close the image.
I'm using the enthought package (for mac), but the error comes from the pylab/scipy.
The error the appears is exactly:
$ lpha $ (at char 0), (line:1, col:1)
However, if use the \mu or \gamma, it works well!! I only found about this problem on \beta and \alpha.
Does anyone knows what this can be? I believe python is interpreting "\a" as some character... but I don't know how should I debug / avoid it.
The issue is that \a
and \b
have special meaning inside a Python string literal.
I recommend that you use raw strings whenever there is a backslash embedded inside a string:
r'$ \alpha $'
In addition to using raw strings (as mentioned in the post above) you can also escape the backslash. So typing \\alpha
and \\beta
will also work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With