On Tue, 28 Jul 2015 at 16:01 Joao Quinta da Fonseca <
joao.fons...@manchester.ac.uk> wrote:

> I am trying to use LaTeX on the ylabel of a plot using:
>
> plt.ylabel("$\alpha$”)
>
> and I am seeing very inconsistent behaviour. If I use $\alpha$ I get an
> error (see below), but \gamma is fine. $\tau does not give an error but
> plots a strange character.
>

Can you help? thanks
>

This is to do with how Python handles strings and is not a matplotlib
issue. The \ is an escape character in Python strings but only for certain
letters e.g. \t is a tab character etc:

In [3]: print('$\tau$')
$    au$

In [4]: print('$\alpha$')
$lpha$

\g is not an escape so:

In [5]: print('$\gamma$')
$\gamma$

To include slashes in your string you either need to double them up or use
raw strings:

In [8]: print(r'$\alpha$')
$\alpha$

In [9]: print('$\\alpha$')
$\alpha$

--
Oscar
------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to