python matplotlib拟合直线
import numpy as np
import matplotlib.pyplot as plt plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
def linear_regression(x, y):
N = len(x)
sumx = sum(x)
sumy = sum(y)
sumx2 = sum(x ** 2)
sumxy = sum(x * y)
A = np.mat([[N, sumx], [sumx, sumx2]])
b = np.array([sumy, sumxy])
return np.linalg.solve(A, b) #单臂
#修改数据1:
X1=np.array([0,20,40,60,80,100,120,140,160,180,200])
Y1=np.array([0,0.02,0.06,0.1,0.13,0.16,0.19,0.22,0.245,0.278,0.3]) #半桥
#修改数据2:
X2=np.array([0,20,40,60,80,100,120,140,160,180,200])
Y2=np.array([0,0.057,0.118,0.185,0.245,0.308,0.376,0.425,0.488,0.544,0.58]) a0, a1 = linear_regression(X1, Y1)
# 生成拟合直线的绘制点
_X1 = [0, 200]
_Y1 = [a0 + a1 * x for x in _X1] a0, a1 = linear_regression(X2, Y2)
# 生成拟合直线的绘制点
_X2 = [0, 200]
_Y2 = [a0 + a1 * x for x in _X1] #显示图像
plt.plot( X1, Y1, 'ro', linewidth=2,label="单臂电桥")
plt.plot(_X1, _Y1, 'b',linewidth=2,label='单臂电桥',color='C0')
plt.plot( X2, Y2, 'g^', linewidth=2,label='半桥')
plt.plot(_X2, _Y2, 'b', linewidth=2,label='半桥',color='C1')
plt.xlabel('weight/g')
plt.ylabel('voltage/v')
plt.legend()
plt.show()

python matplotlib拟合直线的更多相关文章
- [MXNet逐梦之旅]练习一·使用MXNet拟合直线手动实现
[MXNet逐梦之旅]练习一·使用MXNet拟合直线手动实现 code #%% from matplotlib import pyplot as plt from mxnet import autog ...
- python多项式拟合:np.polyfit 和 np.polyld
python数据拟合主要可采用numpy库,库的安装可直接用pip install numpy等. 1. 原始数据:假如要拟合的数据yyy来自sin函数,np.sin import numpy as ...
- python matplotlib 中文显示参数设置
python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...
- python matplotlib plot 数据中的中文无法正常显示的解决办法
转发自:http://blog.csdn.net/laoyaotask/article/details/22117745?utm_source=tuicool python matplotlib pl ...
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- Python 求点到直线的垂足
Python 求点到直线的垂足 在已知一个点,和一条已知两个点的直线的情况下 运算公式参考链接:https://www.cnblogs.com/mazhenyu/p/3508735.html def ...
- 使用Python matplotlib做动态曲线
今天看到“Python实时监控CPU使用率”的教程: https://www.w3cschool.cn/python3/python3-ja3d2z2g.html 自己也学习如何使用Python ma ...
- python matplotlib 中文显示乱码设置
python matplotlib 中文显示乱码设置 原因:是matplotlib库中没有中文字体.1 解决方案:1.进入C:\Anaconda64\Lib\site-packages\matplot ...
- 【python+opencv】直线检测+圆检测
Python+OpenCV图像处理—— 直线检测 直线检测理论知识: 1.霍夫变换(Hough Transform) 霍夫变换是图像处理中从图像中识别几何形状的基本方法之一,应用很广泛,也有很多改进 ...
随机推荐
- html js 遮罩层
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 25 Flutter仿京东商城项目 购物车页面布局
加群452892873 下载对应25课文件,运行方法,建好项目,直接替换lib目录,在往pubspec.yaml添加上一下扩展. cupertino_icons: ^0.1.2 flutter_swi ...
- Java高并发程序设计
一.并行世界 摩尔定律的失效,2004年秋季,Intel宣布彻底取消4GHz计划,CPU向多核心的发展,顶级计算机科学家唐纳德丶尔文丶克努斯评价:在我看来,这种现象(并发)或多或少是由于硬件设计者已经 ...
- 详解VMware 虚拟机中添加新硬盘的方法
一.VMware新增磁盘的设置步骤 (建议:在设置虚拟的时候,不要运行虚拟机的系统,不然添加了新的虚拟磁盘则要重启虚拟机) 1.选择“VM”----“设置”并打开,将光标定位在“硬盘(SCSI)”这一 ...
- Python项目开发之CMDB理解与分析
CMDB的由来--ITIL ITIL就是IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库),由英国政府部门CC ...
- vmware安装密钥
VMware虚拟机已升级至14版本,之前的12版本的秘钥已经无法使用,在此分享一下VMware Workstation 14永久激活密钥: CG54H-D8D0H-H8DHY-C6X7X-N2KG6 ...
- 【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation
problem 762. Prime Number of Set Bits in Binary Representation solution1: class Solution { public: i ...
- Python扫描器-常用库-Request
1.常用库-Request 1.1. 介绍 #安装:pip3 install requests #各种请求方式:常用的就是requests.get()和requests.post() >> ...
- iOS-AVFoundation生成缩略图
使用MPMoviePlayerController来生成缩略图足够简单,但是如果仅仅是是为了生成缩略图而不进行视频播放的话,此刻使用 MPMoviePlayerController就有点大材小用了.其 ...
- charles 开始/暂停记录
本文参考:charles 开始/暂停记录 1.1. stop/start recording 和 2.1 recording settings 是常用的功能了:这里需要注意就是后面的session1代 ...