在Python的matplotlib中从散点图绘制曲线?

2024-05-04 11:18:41 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

我的问题:

如何通过这些数据绘制曲线,从而描述此图的方程式。。

我用下面的代码生成了这个散点图,但是我不知道如何为这个数据生成一个方程,同时在这个图上绘制相应的曲线。请帮忙。!

def draw(data,xlabel,ylabel):
    print('length of data : ',len(data))
    x,y = [],[]
    for i in data:
        x.append((i[1]))
        y.append((i[0]))
    plt.scatter(x, y,marker=r'o',color='b')
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.show()

基本上我想要这样的东西:enter image description here


Tags: 数据datadef绘制pltlength曲线代码生成