(1)找到matplotlibrc文件
(2)修改font.sefi和font.sans-serif(在字体FONT下)
修改为
font.serif: DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
font.sans-serif: DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
一般在数据绘图时,数据的坐标轴部分容易会出现负数
示例代码:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']#设置字体
x = np.linspace(-5, 5, 100)
y = np.cos(x)
plt.plot(x, y)
plt.show()
绘图发现,数据的负号部分无法正常显示,变成方框,且编译器发出提示
解决方法:
加入一段代码
plt.rcParams['axes.unicode_minus'] =False