Reputation: 357
I'm trying to generate a plot using Matplotlib with a non-Latin character (a "μ") in an axis label, like this:
matplotlib.pyplot.xlabel(u'Sarcomere Length (μm)')
I'm using the Cairo renderer on Linux and I'm getting a "box" instead of "μ":
It works with accented Latin characters (like "é"). Any ideas?
Upvotes: 5
Views: 3148
Reputation: 284820
It's a font problem. Whatever font you have set as matplotlib's default doesn't have that particular character. There are a number of ways to potentially fix this, but it's going to be fairly system dependent. (It may be as simple as ensuring that you have the appropriate font package installed.)
You can set the fonts that matplotlib will use in your .matplotlibrc file. If it doesn't find the exact font you're trying to use, you can specify the full path to the appropriate .ttf font file in the .matplotlibrc file. Usually you won't need to do this, though.
However, there's a simpler way, in the particular case you specified above.
Generally speaking, you're better off using matplotlib's mathtext rendering for things like greek symbols. E.g. do matplotlib.pyplot.xlabel(r'Sarcomere Length ($\mu m$)')
instead.
Upvotes: 7