数据处理

这段内容展示了如何使用numpy创建数据数组,并结合matplotlib进行数据的初步和进一步修饰的图像绘制,包括直线拟合和图表装饰。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入代码片
import matplotlib.pyplot as plt
import numpy as np
data = [
-1.33,-1.20,-1.09,-1.10,-0.99,-0.94,-0.89,-0.83,-0.71,
-0.70,-0.58-0.51,-0.47,-0.40,-0.27,-0.18,-0.12,-0.03,
-0.00,
+0.08,+0.16,+0.23,+0.30,+0.37,+0.43,+0.50,+0.56,+0.62,+0.68,+0.74,+0.79,+0.84,+0.90,+0.94,+0.97,+0.99,+0.99,
]
data = np.array(data)
x = np.linspace(0,20,len(data))
plt.figure(figsize=(12,12))
plt.plot(x,data,‘r*’)
plt.show()

在这里插入图片描述

进一步修饰图像

x = np.linspace(0,20,len(data))
A = np.vstack([x, np.ones(len(x))]).T
m, c = np.linalg.lstsq(A, data)[0]
plt.figure(figsize=(8,8))
plt.plot(x, mx+c, ‘r’, label=‘Fitted line’)
plt.plot(x,data,'b
’,label=‘Original data’)
plt.xlabel(‘DataX’)
plt.ylabel(‘DataY’)
plt.title(‘Ex’)
plt.grid()
plt.show()
D:\Ana\Win_A6\lib\site-packages\ipykernel_launcher.py:4: FutureWarning: rcond parameter will change to the default of machine precision times max(M, N) where M and N are the input matrix dimensions.
To use the future default and silence this warning we advise to pass rcond=None, to keep using the old, explicitly pass rcond=-1.
after removing the cwd from sys.path.
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值