09 Python Matplotlib Chinese display method

# plt.plot(x(x轴数据,列表或数组),y(y轴数据,列表或数组),
  
plt.plot([3, 1, 4, 4 ,8, 2]) 
plt.axis([0, 10, 0, 10]) # x轴开始于 -1 结束于 10 ;y轴开始于 0 结束于 16
## plt.subplot(nrows, ncols, plot_number)
plt.subplot(3, 2, 4) #分栏绘制
plt.ylabel('grade')
plt.xlabel('years')
plt.savefig('test', dpi = 600) # PNG储存



def f (t):
  return np.exp(-t)*np.cos(2*np.pi*t)
a = np.arange(0.0, 5.0, 0.02)
plt.subplot(3, 2, 1)
plt.plot(a, f(a))

plt.subplot(3, 2, 2)
plt.plot(a, np.cos(2*np.pi*f(a)), '--')


## plt.plot(x(x轴数据,列表或数组),y(y轴数据,列表或数组)
 # format_string(控制曲线的格式字符串),**kwarge(第二组或更多,x,y,format_string))
a = np.arange(10)
plt.subplot(3, 2, 3)
color = 'green'
linestyle = 'dashed'
marker = 'o'
markerfacecolor:
markersize:
plt.plot(a, a*1.5, 'go-',a, a*2.5,'rx', a,a*3.5,'*', a,a*4.5,'b-.')

Chinese display method

The first method

rcParams['font.family'] 用于显示字体的名字
'SimHei' = 中文黑体
'Kaiti' = 中文楷体
'LiSu' = 中文隶书
'FangSong' = 中文仿宋
'YouYuan' = 中文幼圆
'C' = 华文宋体
rcParams['font.style']  字体风格,正常‘normal’或‘italic’
rcParams['font.size']  字体大小,整数字号或者‘large’,‘x - small’
matplotlib.rcParams['font.style'] = 'italic'
matplotlib.rcParams['font.family'] = 'SimHei' # 修改rcParams实现中文字体显示
matplotlib.rcParams['font.size'] = '5'
plt.show()

The second method

plt.subplot(3, 2, 5)

a = np.arange(0, 0.5, 0.02)
plt.xlabel("横轴: 时间", fontproperties = 'SimHei',fontsize = 10)
plt.ylabel("纵轴:振幅", fontproperties = 'SimHei',fontsize = 10)
plt.plot(a, np.cos(2*np.pi*a), "--")

plt.savefig('test', dpi = 600)

Text display method

plt.xlabel x-axis labeling

plt.ylabel () Y-axis labeling

plt.title () adds a title to the overall graphic

plt.text () Add text at any position

plt.annotate () adds a note with arrow to the graph

plt.annotate (s (annotation content), xy = arrow_crd (), xytext = text_crd (location of text), arrowprops = dict (arrow attribute))

plt.subplot()

a = np.arange(0, 5, 0.2)
plt.xlabel("横轴: 时间", fontproperties = 'SimHei',fontsize = 10, color = 'green')
plt.ylabel("纵轴:振幅", fontproperties = 'SimHei',fontsize = 10)
plt.title(r'正弦波实例 $y = cos(2\pi x)$', fontproperties = 'SimHei', fontsize = 15)
plt.text (2, 1, r'$\mu = 100$', fontproperties = 'SimHei', fontsize = 10)
plt.annotate(r'$\mu = 100$', xy = (2, 1), xytext = (3, 1.5),
             arrowprops = dict(facecolor = 'black', shrink = 0.01, width = 2))
plt.axis([-1,6, -2, 2])
plt.grid(True)
plt.plot(a, np.cos(2*np.pi*a), "--")

plt.savefig('test', dpi = 600)
plt.show()
Published 36 original articles · praised 0 · visits 613

Guess you like

Origin blog.csdn.net/Corollary/article/details/105499565