python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法
生活随笔
收集整理的這篇文章主要介紹了
python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- 遇到的問(wèn)題
- 解決方法
- 參考
解決方法:在畫圖前添加這樣一句代碼
plt.rcParams['font.sans-serif'] = ['SimHei']遇到的問(wèn)題
環(huán)境:win10,編輯器Geany,遇到的問(wèn)題
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)所運(yùn)行的代碼
import csv import matplotlib.pyplot as pltfilename = 'data/sitka_weather_2018_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)# 根據(jù)最高溫度繪制圖形 plt.style.use('seaborn') plt. fig, ax = plt.subplots() ax.plot(highs, c='red')# 設(shè)置圖形格式 ax.set_title("2018年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()運(yùn)行結(jié)果:標(biāo)題上的中文是亂碼
解決方法
加上下面這句話:
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')參考
總結(jié)
以上是生活随笔為你收集整理的python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python基础学习[python编程从
- 下一篇: python项目ImportError: