【发布时间】:2016-12-04 08:00:58
【问题描述】:
我正在尝试使用matplotlib 库创建直方图。
我将编码设置为 UTF-8,但缺少一些波兰语字符(不是全部,只有一些)。
我试过玩encode 和decode,但没有成功。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import matplotlib.pyplot as plt
#sampleData
data=[[ 0.13837092, 0.14755699, 0.17719047, 0.1998352 ],
[ 0.19318216, 0.15863521, 0.17136143, 0.18979461]]
n, bins, patches = plt.hist(data, facecolor='green')
# I've tried also adding: .encode('UTF8') and .decode('UTF8'), but without success
plt.xlabel("Wartości ą, ć, ę, ł, ń, ó, ś, ź, ż.")
plt.ylabel("Prawdopodobieństwo ą, ć, ę, ł, ń, ó, ś, ź, ż.")
plt.title("Tytuł ą, ć, ę, ł, ń, ó, ś, ź, ż.")
plt.grid(True)
plt.savefig("sampleHist.png")
plt.clf()
【问题讨论】:
-
编码没问题。但是您使用的字体不包含这些字符。重复的问题解释了如何更改 matlabplot 中使用的字体。
标签: python matplotlib character-encoding