fig = plt.figure(figsize=(7,7))
plt.subplot(211)
x = np.arange(-1,1.01,0.02)
# linewidth lw 1 2 3
plt.plot(x,np.sin(x * np.pi ))
# x = np.arange(-1,1.01,0.5) * np.pi
x = np.linspace(-1,1,5)
plt.plot(x,np.sin(x * np.pi),'o')
# 文本,参数1 x位置, 参数2 y位置 参数3 文本(支持latex公式,公式中不支持中文)
plt.text(0.3,0.5,r'点:$ \frac{\pi}{2} $',fontsize=24,c='#e3a233')
fig = plt.figure(figsize=(7,7))
plt.subplot(212)
x = np.arange(-1,1.01,0.02)
# linewidth lw 1 2 3
plt.plot(x,np.cos(x * np.pi ))
# x = np.arange(-1,1.01,0.5) * np.pi
x = np.linspace(-1,1,5)
plt.plot(x,np.cos(x * np.pi),'o')
# 文本,参数1 x位置, 参数2 y位置 参数3 文本(支持latex公式,公式中不支持中文)
plt.text(0.6,0.5,r'点:$ \frac{\pi}{2} $',fontsize=24,c='#e3a233')
# 注释
plt.annotate(r'$ (0,1) $',
xy = (0,1),
xytext = (-0.1,0.2),
fontsize = 18,
color = '#e3a233',
arrowprops=dict(arrowstyle='-|>',color='#e3a233')
)
fig = plt.figure(figsize=(10,5))
x = np.linspace(-1,1,100)
plt.plot(x,np.sin(x * np.pi))
# 刻度
plt.xticks([-1,-0.5,0,0.5,1],
labels=[
r'$ -\pi $',
r'$ -\frac{\pi}{2} $',
r'$ 0 $',
r'$ \frac{\pi}{2} $',
r'$ \pi $'
],fontsize=24,rotation=-30)
plt.grid(ls='-.',c='b',alpha=0.3,axis='y')
plt.show()
# 网格
fig = plt.figure(figsize=(10,5))
x = np.linspace(-1,1,100)
plt.plot(x,np.sin(x * np.pi))
# ls 线型 c 颜色 alpha 透明度 axis=([x,y])
plt.grid(ls='-.',c='b',alpha=0.1,axis='x')
plt.show()
# 网格
fig = plt.figure(figsize=(10,5))
x = np.linspace(-1,1,100)
plt.plot(x,np.sin(x * np.pi))
plt.axhline(y=0,ls='-')
plt.axvline(x=0,ls='-')
plt.axvline()
plt.show()
# 网格
fig = plt.figure(figsize=(10,5))
x = np.linspace(-1,1,100)
plt.plot(x,np.sin(x * np.pi))
plt.axhspan(ymin=-0.5,ymax=0.5,facecolor='#f5f5f5')
plt.axvspan(xmin=-0.25,xmax=0.25,facecolor='#f5f5f5')
plt.show()
留言