2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法

python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法

时间:2019-03-23 14:44:05

相关推荐

python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法

文章目录

遇到的问题解决方法参考

解决方法:在画图前添加这样一句代码

plt.rcParams['font.sans-serif'] = ['SimHei']

遇到的问题

环境:win10,编辑器Geany,遇到的问题

C:\Users\m1521\AppData\Roaming\Python\Python38\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 24180 missing from current font.font.set_text(s, 0.0, flags=flags)

所运行的代码

import csvimport matplotlib.pyplot as pltfilename = 'data/sitka_weather__simple.csv'with open(filename) as f:reader = csv.reader(f)header_row = next(reader)# 从文件中获取最高温度highs = []for row in reader:high = int(row[5])highs.append(high)# 根据最高温度绘制图形plt.style.use('seaborn')plt.fig, ax = plt.subplots()ax.plot(highs, c='red')# 设置图形格式ax.set_title("7月每日最高温度", fontsize=24)ax.set_xlabel('', fontsize=16)ax.set_ylabel("温度(F)", fontsize=16)ax.tick_params(axis='both', which='major', labelsize=16)plt.show()

运行结果:标题上的中文是乱码

解决方法

加上下面这句话:

plt.rcParams['font.sans-serif'] = ['SimHei']

添加位置位于plot前面

plt.style.use('seaborn')plt.rcParams['font.sans-serif'] = ['SimHei']fig, ax = plt.subplots()ax.plot(highs, c='red')

参考

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。