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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

matplotlib显示中文字体

發布時間:2023/12/31 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matplotlib显示中文字体 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原始地址:http://zanyongli.i.sohu.com/blog/view/195716528.htm

matplotlib 1.0.0版

對于3.0的可能不太適用,要注意語法結構!

C:/Python26/Lib/site-packages/matplotlib/mpl-data/matplotlibrc文件(Windows) /usr/share/matplotlib/mpl-data/matplotlibrc (Linux): font.family : sans-serif #打開該選項 font.sans-serif : Microsoft YaHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif #添加“Microsoft YaHei”,該行指示缺省字體注:在font.sans-serif中添加的字體名稱必須正確,可以在
$HOME/.matplotlib/fontList.cache C:/Users/用戶名/.matplotlib/fontList.cache文件中 ,通過查找文件名找到對應的名稱,如上面的"Microsoft YaHei"的字體文件名稱為“msyh.ttf",搜索一下就找到了。一些可用的字體名稱見示例代碼.
如果還不行,試著將字體文件copy到
/usr/share/matplotlib/mpl-data/fonts/ttf(Windows)
C:/Python26/Lib/site-packages/matplotlib/mpl-data/fonts/ttf(Linux)
目錄下,再試。示例代碼如下:
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt plt.figure(figsize=(8,4)) a = plt.text(0.05, 0.05, u"直線和二次曲線的交點") #Microsoft YaHei,FangSong,YouYuan,SimHei,STKaiti,STSong,SimSun-ExtB,Webdings plt.text(0.05, 0.95, u "STSong直線", fontproperties='STSong' ) plt.text(0.05, 0.85, u"STKaiti直線", fontproperties='STKaiti') plt.text(0.05, 0.75, u"FangSong直線", fontproperties='FangSong') plt.text(0.05, 0.65, u"YouYuan直線", fontproperties='YouYuan') plt.text(0.05, 0.55, u"SimHei直線", fontproperties='SimHei') plt.text(0.05, 0.45, u"Microsoft YaHei微軟雅黑", fontproperties='Microsoft YaHei') plt.text(0.05, 0.35, u"STCaiyun華文彩云", fontproperties='STCaiyun') plt.show()
注意: 字符串,都用u"..."的形式.(文件編碼utf-8 加上" # coding = utf-8 ?"一行.)


總結

以上是生活随笔為你收集整理的matplotlib显示中文字体的全部內容,希望文章能夠幫你解決所遇到的問題。

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