[英]unicode text when using savefig() in matplotlib
I am new to matplotlib and trying to plot a 2D/3D chart with non-ASCII texts in it, I am able to use show()
to plot on screen: 我是matplotlib的新手并尝试在其中绘制带有非ASCII文本的2D / 3D图表,我可以使用show()
在屏幕上绘图:
plt.text(X, Y, str(text[i].decode('utf-8')) )
plt.show()
However when I try to save the figure to a file with savefig()
, all texts become little squares []
但是,当我尝试使用savefig()
将图形保存到文件时,所有文本都变成小方块[]
I am sure it is a font related problem but I can't see to figure out how to fix this. 我确信这是一个字体相关的问题,但我无法弄清楚如何解决这个问题。
I am on a Mac OSX 10.10.5, if that matters. 我在Mac OSX 10.10.5上,如果这很重要的话。
finally solved it by using: 终于通过使用:
fontpath = '/Library/Fonts/华文细黑.ttf'
properties = font_manager.FontProperties(fname=fontpath)
matplotlib.rcParams['font.family'] = properties.get_name()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.