|
From: Joao Q. da F. <Joa...@ma...> - 2015-07-28 15:12:15
|
That makes sense. Thank you.
João
> On 28 Jul 2015, at 16:08, Oscar Benjamin <osc...@gm...> wrote:
>
>
>
> On Tue, 28 Jul 2015 at 16:01 Joao Quinta da Fonseca <Joa...@ma...> 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
|