1.序
使用matplotlib绘图时,当缺少中文字体或Times New Roman的解决方案,因为论文排版要求以Times New Roman为多。
2.解决方案
当你的系统中无某个字体,先打印出系统支持的所有字体,然后再用相近的字体替换。代码如下,使用STIXGeneral代替Times New Roman。还有一法是安装指定的字体。
import matplotlib.font_manager as font_manager fonts = [font.name for font in font_manager.fontManager.ttflist] print(fonts) plt.rcParams['font.family'] = 'STIXGeneral'