python绘图-中文字体

python绘图-中文字体,第1张

需要首先下载所需字体

黑体:simhei.ttf
宋体:SimSun.ttf

# 黑体
from matplotlib import pyplot as plt

from matplotlib.font_manager import FontProperties
# 在此设置字体及大小
font = FontProperties(fname=r"./simhei.ttf", size=14) 

plt.figure()
plt.xlabel(u'x轴', FontProperties=font)
plt.ylabel(u'y轴', FontProperties=font)
plt.title(u'test——绘图', FontProperties=font)
import numpy as np
plt.plot(np.arange(1, 10), np.arange(1, 10))


宋体:

# 宋体
from matplotlib import pyplot as plt

from matplotlib.font_manager import FontProperties
# 在此设置字体及大小
font = FontProperties(fname=r"./SimSun.ttf", size=14) 

plt.figure()
plt.xlabel(u'x轴', FontProperties=font)
plt.ylabel(u'y轴', FontProperties=font)
plt.title(u'test——绘图', FontProperties=font)
import numpy as np
plt.plot(np.arange(1, 10), np.arange(1, 10))

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/918190.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存