Giter Site home page Giter Site logo

py_matplotlib_note's Introduction

如何修正 python 中 matplotlib 套件顯示中文的問題

請參考以下快速可行的方案:

  1. 請確認您有安裝 matplotlib 套件。

  2. 打開命令提示字元 Command Prompt, 輸入下列指令:

    python -c "print(__import__('matplotlib').matplotlib_fname())"

    或是在命令提示字元輸入 python (或 python3) 按下 Enter,然後在 >>> 的提示字元 後,分別輸入以下兩行指令:

    import matplotlib print(matplotlib.matplotlib_fname())

  3. 檢視上述的輸出結果。這是 matplotlib 的設定檔。輸出結果會類似於:

    C:\Users<username>\AppData\Local\Programs\Python\Python38\lib \site-packages\matplotlib\mpl-data\matplotlibrc

  4. 用 Notepad 或文字編輯器開啟上述的 matplotlibrc 設定檔,找到開頭為:

   #font.serif    #font.sans-serif

這兩行。

  1. 編輯這個檔案。移除這兩行前面的 #。

  2. 在上述兩行的 "DejaVu Serif" 前加入

    "Microsoft JhengHei, " (不含引號)。

  3. 接著繼續找到下列開頭為 # axes 這行:

    #axes.unicode_minus

  4. 移除這行前的 #。

  5. 修改這行結尾的 True 為 False (這樣圖片中可以顯示負號)。

  6. 將修改上述內容後的 matplotlibrc 設定檔存檔。

  7. 在開始功能表,按右鍵,選[執行]。輸入 %userprofile%。按下[確定]。

  8. 找到 %userprofile%.matplotlib 目錄。這是快取檔案。刪除這個目錄。

  9. 到步驟2)的

    lib\site-packages\matplotlib_pycache_

    這個__pycache__目錄。這是快取檔案。刪除這個目錄。

  10. 在開始功能表,按右鍵,選[執行]。輸入 fonts。按下[確定]。

  11. 在搜尋輸入 "Microsoft JhengHei"。找到後點取它後,按右鍵,選[複製]。

  12. 開啟在步驟2)的

lib\site-packages\matplotlib\mpl-data\ 下的 fonts\ttf 目錄資料夾。

  1. 貼上剛才的 "Microsoft JhengHei" 字形檔案(可能有3個)。

  2. 好了。重新啟動你的程式。套件會重新產生步驟 11 和 步驟 12 的目錄。

py_matplotlib_note's People

Contributors

jacquesblazor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.