在项目的一部分中,我需要描绘一些符号 . 但是,一些符号未正确显示/保存 .
import matplotlib.pyplot as plt
%matplotlib inline
plt.subplots(1,1, facecolor='w', dpi = 150)
plt.text(0.1, 0.9, ['This is a test', "⭘" , '◔'])
plt.text(0.1, 0.8, ['This is a test', "⭘" , '◔'], fontname = 'Arial')
plt.text(0.1, 0.7, ['This is a test', "⭘" , '◔'], fontname = 'SimHei')
plt.yticks([0,0.5,1],["⭘",'◔','⏺'])
plt.savefig('unicode_error.png')
plt.show()
结果如下,其中图表未显示某些符号:
我在Win10中运行,我尝试了两个后端:nbAgg和backend_inline .
Two main questions:
1.如何解决显示"⭘"或"⏺"的主要问题?
2.如何将默认字体更改为 matplotlib.font_manager
中未包含的字体(在我的情况下为"SimHei")?目前,我收到以下警告:C:\ Users \ mabag \ AppData \ Local \ Continuum \ anaconda3 \ lib \ site-packages \ matplotlib \ font_manager.py:1328:UserWarning:findfont:找不到字体系列['SimHei'] . 回到DejaVu Sans(prop.get_family(),self.defaultFamily [fontext]))
2 回答
使用中的Font需要实际提供unicode符号 . 在这里你可能想要使用
要么
花了好几个小时后,我找到了解决方案:
但是,最重要的一点是删除chached
.matplotlib
文件夹 . Te文件夹通常位于c:\users\your_username\.matplotlib
(在Windows中)或home\.matplotlib
(在Linux中) .