python绘图-中文字体

需要首先下载所需字体

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

# 黑体
from matplotlib import pyplot as plt

from matplotlib.font_manager import FontProperties
# 在此设置字体及大小
font = FontProperties(fname=r"/root/whq/font/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"/root/whq/font/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))

在这里插入图片描述


版权声明:本文为whq___原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。