from pylab import mpl
import numpy as np

mpl.rcParams['font.sans-serif'] = ['SimHei'] # 指定默认字体  
  
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号 '-' 显示为方块的问题  
%pylab inline
t = np.arange(-5 * np.pi, 5 * np.pi, 0.01)  
y = np.sin(t)/t  
plt.plot(t, y)  
plt.title(u'这里写的是中文')  
plt.xlabel(u'X坐标')  
plt.ylabel(u'Y坐标')  
plt.show()  

matplotlib 中文显示 的问题

第二种方法

from matplotlib.font_manager import FontManager
fm = FontManager()
mat_fonts = set(f.name for f in fm.ttflist)
myfont = matplotlib.font_manager.FontProperties(fname='C:/Windows/Fonts/msyh.ttf')  
mpl.rcParams['axes.unicode_minus'] = False  
t = np.arange(-5 * np.pi, 5 * np.pi, 0.01)  
y = np.sin(t)/t  
plt.plot(t, y)  
plt.title(u'这里写的是中文')  
plt.xlabel(u'X坐标')  
plt.ylabel(u'Y坐标')  
plt.show()  

matplotlib 中文显示 的问题

相关文章:

  • 2021-12-15
  • 2021-07-07
  • 2021-05-23
  • 2021-10-25
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2021-04-28
  • 2021-11-10
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案