I try to show:
...as my plots' x axis label. For this purpose I use the pylab.figtext()
function, i.e:
py.figtext(0.5, 0.05, "$k=2,\left \langle \left | -k \right |;k \right \rangle,
k\in \mathbb{N}_{+}\cup\left \{ 0 \right \}$", rotation='horizontal', size='12')
Unfortunately, I get error:
ValueError:
$k=2,\left \langle \left | -k
ight |;k
ight
angle, k\in \mathbb{N}_{+}\cup\left \{ 0
ight \}$
^
Expected end of text (at char 0), (line:1, col:1)
Why is that? I thought, that I can use LaTeX freely. How should I format my text in figtext()
method in order to achieve the aforementioned mathematical sentence? Thank you in advance.
This can be fixed by a 1 letter correction:
py.figtext(0.5, 0.05, r"$k=2,\left \langle \left | -k \right |;k \right \rangle,
k\in \mathbb{N}_{+}\cup\left \{ 0 \right \}$", rotation='horizontal', size='12')
Note the r before the string literal. The cause of the error is that several of the character combinations in your latex string are valid Python escape sequences for such things as tabs and new-lines. A string literal prefixed with an r (e.g. r"foo\nbar"
) makes Python interpret the string as a raw string literal, i.e. without converting the escaped character combinations to special characters.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments