日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2025/4/5 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 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)# 根據最高溫度繪制圖形 plt.style.use('seaborn') plt. fig, ax = plt.subplots() ax.plot(highs, c='red')# 設置圖形格式 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()

運行結果:標題上的中文是亂碼

解決方法

加上下面這句話:

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')

參考

總結

以上是生活随笔為你收集整理的python出现中文乱码 RuntimeWarning: Glyph 24180 missing from current font.解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。