2
我想在Seaborn中使用Unicode文本。 (Python 2.7)在seaborn中使用Unicode文本
我可以使用Unicode文本作为matplotlib的图块。 例如,
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
fp = FontProperties(fname='/usr/share/fonts/truetype/takao-gothic/TakaoGothic.ttf')
text = u'bădărău'
plt.plot([1,2,3,2], label=text)
plt.legend(prop=fp)
如何设置这种字体属性来seaborn? 其实,我想用Unicode文本为注释,如下例所示:
import seaborn as sns
import numpy as np
sns.heatmap(np.array([[1,2,3]]), annot=np.array([['a', 'b', 'c']]), fmt='')
# want to use ă instead of a
如果我使用ă
,我收到以下错误
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128)
您可能会觉得这篇文章有用:[Pragmatic Unicode](http://nedbatchelder.com/text/unipain.html),它是由SO老手Ned Batchelder编写的。 –