UserWarning: Glyph 21435 (\N{CJK UNIFIED IDEOGRAPH-53BB}) missing from font(s) DejaVu Sans.

matplotlib警告,对于这种警告。

UserWarning: Glyph 21435 (\N{CJK UNIFIED IDEOGRAPH-53BB}) missing from font(s) DejaVu Sans._第1张图片

原因是:matplotlib 使用的默认字体 DejaVu Sans 不支持中文字符,因此在渲染带有中文的图表时会出现警告。

此时只需要在库文件中,加入两行代码:

UserWarning: Glyph 21435 (\N{CJK UNIFIED IDEOGRAPH-53BB}) missing from font(s) DejaVu Sans._第2张图片

import matplotlib.pyplot as plt
from matplotlib import rcParams

# 设置字体为 SimHei(黑体),支持中文
rcParams['font.sans-serif'] = ['SimHei']  # 使用黑体
rcParams['axes.unicode_minus'] = False   # 避免坐标轴负号显示问题

 字体改为黑体,即可解决。以后写python文件都加上这两行就好啦。

还有一种代码也可以用:

import matplotlib.pyplot as plt import matplotlib # 设置支持中文的字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 使用黑体 plt.rcParams['axes.unicode_minus'] = False # 防止负号显示问题

你可能感兴趣的:(python)