python - Non-ASCII characters in Matplotlib -
i have problem displaying non-ascii characters in matplotlib, these characters rendered small boxes instead of proper font, looks (i filled these boxes red paint hightlight them):
how fix it?
a related question accented characters in matplotlib.
this problem may have couple of different causes:
the default font not include these glyphs
you may change default font using following (before plotting done!)
matplotlib.rc('font', family='arial')
in versions of matplotlib you'll have te set family:
matplotlib.rc('font', **{'sans-serif' : 'arial', 'family' : 'sans-serif'})
(note because sans-serif
contains hyphen inside **{}
syntax, necessary.)
the first command changes sans-serif
font family contain 1 font (in case arial), second sets default font family sans-serif
.
other options included in documentation.
you have improperly created/passsed string objects matplotlib
even if font contains proper glyphs, if forgot use u
create unicode constants, matplotlib have behaviour:
plt.xlabel("Średnia odległość między stacjami wsparcia modelowaną [km]")
so need add u
:
plt.xlabel(u"Średnia odległość między stacjami wsparcia modelowaną [km]")
another cause forgot put utf-8 magic comment on top of file (i read might source of problem):
# -*- coding: utf-8 -*-
Comments
Post a Comment