简体   繁体   English

plot y 轴相对于 x 轴的导数 python pandas

[英]plot derivative of y-axis against x-axis python pandas

I have the graph below, which is a result of a plot of a two-column data frame, which I'm simply plotting as我有下面的图表,它是两列数据框的 plot 的结果,我只是将其绘制为

df.plot(style='o-')

EDIT编辑

And I plot the running average of it (thanks to the help of people below) with: df.rolling(5).mean()我 plot 它的运行平均值(感谢下面的人的帮助): df.rolling(5).mean()

Can I use some function from pandas to plot the derivative of the y-axis over the x-axis?我可以使用一些 function 从pandas到 plot y 轴在 x 轴上的导数吗?

I've tried the solution proposed here: python pandas: how to calculate derivative/gradient But it didn't work我已经尝试过这里提出的解决方案: python pandas:如何计算导数/梯度但它没有用

在此处输入图像描述

What you would like to have may not be 'average' but 'smoothing' or 'regression', google for those terms can give you more relevent result.您想要的可能不是“平均”,而是“平滑”或“回归”,这些术语的谷歌可以为您提供更相关的结果。

As for your question, Savitzky–Golay filter could be a good tool to use here, it does convolution "by fitting successive sub-sets of adjacent data points with a low-degree polynomial".至于您的问题, Savitzky–Golay 滤波器可能是一个很好的工具,它可以“通过用低次多项式拟合相邻数据点的连续子集”来进行卷积。

In Python you can use scippy.signal.savgol_filter to get the smoothed points.在 Python 中,您可以使用scippy.signal.savgol_filter来获得平滑点。
The derivative would be more tricky though,a workaround would be calculate the slope with convoluted signal(points).但是,导数会更加棘手,解决方法是使用卷积信号(点)计算斜率。

Like already explained, it seams that you want to apply same kind of filter instead of run an average (that in your case should return a number).就像已经解释的那样,它接缝你想要应用相同类型的过滤器而不是运行平均值(在你的情况下应该返回一个数字)。 To start, you can try a simple moving average doing:首先,您可以尝试一个简单的移动平均线:

df.rolling(5).mean()

Where 5 is the window.其中 5 是 window。

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

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