iT邦幫忙

2

請問在python中圖形Matplotlib如何顯示中文?

Zoey 2019-03-27 22:42:0419120 瀏覽

如題
我的版本是Python 3.6.5
看了課本中的方法
也參考了網路上許多文章的作法
都沒有辦法顯示出中文..

https://ithelp.ithome.com.tw/upload/images/20190327/20115739pbdej7QC3g.png

https://ithelp.ithome.com.tw/upload/images/20190327/20115739CFAh9N2NDh.png

https://ithelp.ithome.com.tw/upload/images/20190327/20115739TmbuFVgQsU.png

https://ithelp.ithome.com.tw/upload/images/20190327/20115739TtDnCHnTR5.png

請問還有甚麼方法可以做嗎?
還是我有地方做得不對呢...?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
froce
iT邦大師 1 級 ‧ 2019-03-28 08:22:58

照這篇

from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei'] 
plt.rcParams['axes.unicode_minus'] = False
# 上面這兩句有設應該就行了

plt.plot((1,2,3),(4,3,-1))
plt.title("聲量圖")
plt.ylabel("文章數量")
plt.xlabel("品牌名稱") 
plt.show()

另外不知道你是啥OS,不同OS有差。可能是font沒抓到。
建議把code顯示部分拿出來看一下。

Zoey iT邦新手 4 級 ‧ 2019-03-28 17:44:40 檢舉

感謝回答!!
我一開始也是參考這篇文章
但是後來一直沒有成功
但是剛剛測試後就可以了!!
可能是需要重新開機才行(?
/images/emoticon/emoticon41.gif/images/emoticon/emoticon41.gif

我要發表回答

立即登入回答