日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

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

發布時間:2025/4/5 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

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