简体   繁体   English

绘制每个 x 值的平均值

[英]plot the average of every x value

I plot a function which is based on the results of a curve fit I did in the query.我绘制了一个基于我在查询中所做的曲线拟合结果的函数。 Now I want to see how the curve fit actually fits the average values for every x value.现在我想看看曲线拟合实际上如何拟合每个 x 值的平均值。 I treid it with a for loop and a groupby.我用 for 循环和 groupby 测试它。

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
plt.style.use('seaborn-colorblind')

x = dataset['mrwSmpVWi']
c = dataset['c']
a = dataset['a']
b = dataset['b']
Snr = dataset['Seriennummer']


dataset["y"] = (c / (1 + (a) * np.exp(-b*(x))))

for number in dataset.groupby('mrwSmpVWi'):
    dataset['m'] = dataset['mrwSmpP'].mean()

fig, ax = plt.subplots(figsize=(30,15))

for name, group in dataset.groupby('Seriennummer'):
    group.plot(x="mrwSmpVWi", y="m", ax=ax, marker='o', linestyle='', ms=12, label =name)
    group.plot(x="mrwSmpVWi", y="y", ax=ax, label =name)

plt.show()

The dataset with the values is huge and not sorted by mrwSmpVWi.包含值的数据集很大,并且没有按 mrwSmpVWi 排序。

Has someone an idea why I only get a straight line for my average values?有人知道为什么我的平均值只能得到一条直线吗? 在此处输入图片说明

You got to take a look at what you're doing with this line:你必须看看你在用这条线做什么:

for number in dataset.groupby('mrwSmpVWi'):
    dataset['m'] = dataset['mrwSmpP'].mean()

You probably want:你可能想要:

dataset['m'] = dataset.groupby('Seriennummer')['mrwSmpVWi'].transform('mean')

(assuming you were intending to calculate the mean of each group of Serienummer) (假设您打算计算每组 Serienummer 的平均值)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM