Python的Matplotlib 设置中文字体,字号

 

1.字体与字号

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
#默认字体为宋体
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = ['NSimSun']

生成需要绘图的数据:

x=np.array([1,2,3,4,5,6])
b= x**2-2*x+1

 设定曲线的标签、横纵坐标、横纵轴名称、图例。
其中的“size = 12”、“fontsize=12”是指12像素,在mpl中,默认单位是像素,而word中的字号单位是磅。1磅=4/3像素,所以size=12对应的是小五号字(9磅)。

plt.plot(x,b,linewidth=1,label = '观测站A')
plt.ylabel('位移',size = 12)
plt.xlabel('时间/秒',size = 12)
plt.yticks(fontproperties = 'Times New Roman', size = 12)
plt.xticks(fontproperties = 'Times New Roman', size = 12)
plt.legend(fontsize=12)

 

 

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2023年12月22日
下一篇 2023年12月22日

相关推荐