I need to put greek letters in labels of a matplotlib plot . how can I do it? For instance, unicode Omega is : u\u03A9
. I use plt.xlabel('label')
Asked
Active
Viewed 414 times
0

Cœur
- 37,241
- 25
- 195
- 267

PsycoPulcino
- 111
- 4
-
Possible duplicate of [Accented characters in Matplotlib](http://stackoverflow.com/questions/2406700/accented-characters-in-matplotlib) – Christian Dean Nov 17 '16 at 00:11
-
what do you get on plot now ? If `plt.xlabel(u'\u03A9')` doesn't work then maybe you need font with this char. – furas Nov 17 '16 at 00:44
2 Answers
2
If you are looking specifically for greek letter, you can use LaTex in-line math formatting commands (i.e. '$\Omega$'
) to produce letter that are in the Latex character map.
import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.arange(1000), np.random.rand(1000), 'b.')
plt.xlabel('$\Omega$', size=16)
Here are good resources for finding LaTex symbols.
- PDF list: https://www.rpi.edu/dept/arc/training/latex/LaTeX_symbols.pdf
- Draw your symbol, get a bunch of LaTex characters: http://detexify.kirelabs.org/classify.html

James
- 32,991
- 4
- 47
- 70
-
Ok, thanks! It gives me the error `ValueError: invalid \x escape`. Do I need to include some modules? – PsycoPulcino Nov 17 '16 at 02:07
-
Without seeing more code, I don't what is causing the error. Did copying the above code not work for you? – James Nov 17 '16 at 02:24
1
I'm not positive about matplotlib, but I would assume that declaring them as unicode strings should work
>>> print u'\u03A9'
Ω

af3ld
- 782
- 8
- 30
-
what do you mean by declaring them? i put in plot() `''u\u03A9' '` , `u'\u03A9'` `u'\u03A9` but none of them worked :\ – PsycoPulcino Nov 17 '16 at 00:32
-
@user129511 I mean putting the `u`in front of the the string like so `u'\u03A9'`. By prefixing the string with a `u`, one is declaring the type of string as unicode. If we were declaring a byte string it would be `b'some bytes'` – af3ld Nov 17 '16 at 18:35