matplotlib庫疑難問題---1、解決中文亂碼問題


matplotlib庫疑難問題---1、解決中文亂碼問題

一、總結

一句話總結:

plt.rcParams["font.sans-serif"]=["SimHei"] # 設置matplotlib庫字體的非襯線字體為黑體
plt.rcParams["font.family"]="sans-serif" # 設置matplotlib庫字體族為非襯線字體
# matplotlib解決中文亂碼:
# 設置matplotlib庫字體的非襯線字體為黑體
plt.rcParams["font.sans-serif"]=["SimHei"]
# 設置matplotlib庫字體族為非襯線字體
plt.rcParams["font.family"]="sans-serif"

 

1、matplotlib庫解決坐標軸負號無法顯示問題?

plt.rcParams['axes.unicode_minus'] =False # 坐標軸負號不顯示的時候用來顯示負號

 

 

 

二、內容在總結中

博客對應課程的視頻位置:1、解決中文亂碼問題-范仁義-讀書編程筆記
https://fanrenyi.com/video/43/371

 

import numpy as np import matplotlib.pyplot as plt x = np.linspace(-1,2,20) y1 = np.e**x-10 y2 = x**5-4 plt.plot(x, y1, 'b-', label='第一條線') plt.plot(x, y2, 'r--', label='第二條線') plt.title('隨便畫的兩條線') plt.xlabel(u'橫坐標') plt.ylabel(u'縱坐標') plt.legend() plt.show() 
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 38543 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 20415 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 30011 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 30340 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 20004 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 26465 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 32447 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 27178 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 22352 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 26631 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 27178 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 22352 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 26631 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 32437 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 32437 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 38543 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 20415 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 30011 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 30340 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 20004 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 26465 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 32447 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 31532 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 19968 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:211: RuntimeWarning: Glyph 20108 missing from current font.
  font.set_text(s, 0.0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 31532 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 19968 missing from current font.
  font.set_text(s, 0, flags=flags)
D:\software\coding\python_software\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:180: RuntimeWarning: Glyph 20108 missing from current font.
  font.set_text(s, 0, flags=flags)

配置matplotlib庫的動態配置,設置字體以解決中文亂碼問題

In [2]:
# matplotlib解決中文亂碼:
# 設置matplotlib庫字體的非襯線字體為黑體 plt.rcParams["font.sans-serif"]=["SimHei"] # 設置matplotlib庫字體族為非襯線字體 plt.rcParams["font.family"]="sans-serif" # matplotlib解決負號無法顯示: # 坐標軸負號不顯示的時候用來顯示負號 plt.rcParams['axes.unicode_minus'] =False x = np.linspace(-1,2,20) y1 = np.e**x-10 y2 = x**5-4 plt.plot(x, y1, 'b-', label='第一條線') plt.plot(x, y2, 'r--', label='第二條線') plt.title('隨便畫的兩條線') plt.xlabel(u'橫坐標') plt.ylabel(u'縱坐標') plt.legend() plt.show() 
In [ ]:
 
 

本系列博客對應課程位置:
1、解決中文亂碼問題-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/371
2、將曲線平滑-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/372
3、matplotlib繪圖核心原理-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/373
4、畫動態圖-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/374
5、保存動態圖-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/375
6、顯示圖片-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/376

7、去掉刻度和邊框-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/383

8、幾個點畫曲線-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/384

9、畫箭頭(綜合實例)-1-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/391

9、畫箭頭(綜合實例)-2-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/392

10、畫直方圖-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/393

11、畫動態直方圖-范仁義-讀書編程筆記
https://www.fanrenyi.com/video/43/394

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM