matplotlib.pyplot 绘图(资料收集,待续)

所有的经典绘图都在这里:

https://matplotlib.org/gallery/index.html

每当自己想用python  画图时 ,需要的是各种情况的图形。

demo1:  可以转化为话3 张图,四张图

import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility
np.random.seed(19680801)

dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t))                 # white noise 1
nse2 = np.random.randn(len(t))                 # white noise 2

# Two signals with a coherent part at 10Hz and a random part
s1 = np.sin(2 * np.pi * 10 * t) + nse1
s2 = np.sin(2 * np.pi * 10 * t) + nse2

fig, axs = plt.subplots(2, 1)
axs[0].plot(t, s1, t, s2)
axs[0].set_xlim(0, 2)
axs[0].set_xlabel('time')
axs[0].set_ylabel('s1 and s2')
axs[0].grid(True)

cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
axs[1].set_ylabel('coherence')

fig.tight_layout()
plt.show()

 运行图片:

 

plt.tight_layout():表示会调整多个子图,使之填充整个图像区域。 

demo2: 只展示一个图:

import numpy as np
import matplotlib.pyplot as plt

# Fixing random state for reproducibility

dt =0.01 
t=np.arange(0,30,dt)

s1= np.sin(2*np.pi*10*t)
s2= np.sin(2*np.pi*20*t)
s3= np.sin(2*np.pi*30*t)

fig,axs=plt.subplots(1,1)
s=s1+s2+s3
plt.plot(t,s)

plt.show()

运行结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值