python - Unicode character render -
i can't find way render unicode characters in matlibplot chart:
# -*- coding: utf-8 -*- import matplotlib.pyplot plt numpy.random import normal itertools import count import matplotlib = {u'\u043f\u0430\u0440\u0435\u0430\u0442\u0430': 0.018144370928201092, u'\u0440\u0435\u043b\u0430\u0442\u0438\u0432\u0438\u0442\u0438\u0441\u0442\u0438\u0447\u043a\u0430\u0442\u0430': 0.008406336989671147, u'\u043d\u0430\u043e\u0453\u0430': 0.0704839024518581, u'\u0444\u0438\u0437\u0438\u043a\u0430': 0.025219010969013446, u'\u043a\u043e\u0438': 0.0039908251856718025, u'\u0438\u0437\u0431\u0443\u0432\u043d\u0430\u043b\u0430': 0.0035792606713834184, u'\u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0430\u0442\u0430': 0.008406336989671147, u'\u043c\u0438\u043a\u0440\u043e\u0434\u0438\u043c\u0435\u043d\u0437\u0438\u0438': 0.008406336989671147, u'\u0434\u0430\u0432\u0430': 0.016812673979342295, u'\u0441\u0442\u0440\u0430\u043d\u0430': 0.008406336989671147} plt.bar(*zip(*zip(count(), a.values()))) plt.title("some chart") plt.xticks(*zip(*zip(count(0.4), (a.keys())))) plt.xlabel("value") plt.ylabel("frequency") plt.show()
specify font cyrillic characters. example,
import matplotlib mpl mpl.rcparams['font.family'] = 'arial'
your default font might 'helvetica'
, not have glyphs required characters.
import matplotlib.pyplot plt numpy.random import normal itertools import count import matplotlib mpl mpl.rcparams['font.family'] = 'arial' = {u'\u043f\u0430\u0440\u0435\u0430\u0442\u0430': 0.018144370928201092, u'\u0440\u0435\u043b\u0430\u0442\u0438\u0432\u0438\u0442\u0438\u0441\u0442\u0438\u0447\u043a\u0430\u0442\u0430': 0.008406336989671147, u'\u043d\u0430\u043e\u0453\u0430': 0.0704839024518581, u'\u0444\u0438\u0437\u0438\u043a\u0430': 0.025219010969013446, u'\u043a\u043e\u0438': 0.0039908251856718025, u'\u0438\u0437\u0431\u0443\u0432\u043d\u0430\u043b\u0430': 0.0035792606713834184, u'\u043c\u0435\u0445\u0430\u043d\u0438\u043a\u0430\u0442\u0430': 0.008406336989671147, u'\u043c\u0438\u043a\u0440\u043e\u0434\u0438\u043c\u0435\u043d\u0437\u0438\u0438': 0.008406336989671147, u'\u0434\u0430\u0432\u0430': 0.016812673979342295, u'\u0441\u0442\u0440\u0430\u043d\u0430': 0.008406336989671147} plt.bar(*zip(*zip(count(), a.values()))) plt.title("gaussian histogram") plt.xticks(*zip(*zip(count(0.4), a.keys()))) plt.xlabel("value") plt.ylabel("frequency") plt.show()
if don't have arial
font, can generate list of font files known system with
import matplotlib.font_manager font_manager print(sorted(font_manager.findsystemfonts()))
you can try out fonts using
prop = font_manager.fontproperties(fname=path) mpl.rcparams['font.family'] = prop.get_name()
where path
1 of paths returned findsystemfonts()
.
Comments
Post a Comment