简体   繁体   English

如何绘制剧情python的导数?

[英]How to plot the derivative of a plot python?

I use plotly to plot my data by using this function: 我使用plotly通过以下功能来绘制数据:

data_t = []

for mac, dico_data in dict_info.items():
    data_t.append(go.Scatter( x= dico_data["time"], y= dico_data['val'], name=mac ))
    print (data_t)
data = data_t
offline.plot(data_t)

I need to use a set of data points from a graph to find a derivative and plot it. 我需要使用图形中的一组数据点来找到导数并将其绘制出来。 however I don't find how to do that ? 但是我不知道该怎么做? This is an example of my data: 这是我的数据的一个示例:

[Scatter({
    'name': '14:15:92:cc:00:00:00:01',
    'x': [707, 1212, 1616, 1818, 2020, 2121, 2323, 2424, 2525, 6969, 11009, 11716,
          12019, 16059, 16564, 19493, 20099, 23533, 23836, 25149, 29896, 43127,
          45147, 45753, 55045, 66761, 66862, 77467, 81204, 82921, 92718, 104434],
    'y': [1539071748.0, 1539071752.0, 1539071755.0, 1539071757.0, 1539071759.0,
          1539071760.0, 1539071764.0, 1539071765.0, 1539071768.0, 1539071872.0,
          1539071979.0, 1539071998.0, 1539072006.0, 1539072123.0, 1539072137.0,
          1539072226.0, 1539072250.0, 1539072386.0, 1539072398.0, 1539072450.0,
          1539072637.0, 1539073158.0, 1539073243.0, 1539073268.0, 1539073615.0,
          1539074097.0, 1539074101.0, 1539074533.0, 1539074691.0, 1539074763.0,
          1539075159.0, 1539075623.0]
})]
[Scatter({
    'name': '14:15:92:cc:00:00:00:01',
    'x': [707, 1212, 1616, 1818, 2020, 2121, 2323, 2424, 2525, 6969, 11009, 11716,
          12019, 16059, 16564, 19493, 20099, 23533, 23836, 25149, 29896, 43127,
          45147, 45753, 55045, 66761, 66862, 77467, 81204, 82921, 92718, 104434],
    'y': [1539071748.0, 1539071752.0, 1539071755.0, 1539071757.0, 1539071759.0,
          1539071760.0, 1539071764.0, 1539071765.0, 1539071768.0, 1539071872.0,
          1539071979.0, 1539071998.0, 1539072006.0, 1539072123.0, 1539072137.0,
          1539072226.0, 1539072250.0, 1539072386.0, 1539072398.0, 1539072450.0,
          1539072637.0, 1539073158.0, 1539073243.0, 1539073268.0, 1539073615.0,
          1539074097.0, 1539074101.0, 1539074533.0, 1539074691.0, 1539074763.0,
          1539075159.0, 1539075623.0]
})

You can do something similar to the following, taking this sample of your data: 您可以执行以下类似操作,以获取数据样本:

data = {
        'x': [1539071748.0, 1539071752.0, 1539071755.0, 1539071757.0, 1539071759.0,
          1539071760.0, 1539071764.0, 1539071765.0, 1539071768.0, 1539071872.0,
          1539071979.0, 1539071998.0, 1539072006.0, 1539072123.0, 1539072137.0,
          1539072226.0, 1539072250.0, 1539072386.0, 1539072398.0, 1539072450.0,
          1539072637.0, 1539073158.0, 1539073243.0, 1539073268.0, 1539073615.0,
          1539074097.0, 1539074101.0, 1539074533.0, 1539074691.0, 1539074763.0,
          1539075159.0, 1539075623.0],
        'y': [707, 1212, 1616, 1818, 2020, 2121, 2323, 2424, 2525, 6969, 11009, 11716,
              12019, 16059, 16564, 19493, 20099, 23533, 23836, 25149, 29896, 43127,
              45147, 45753, 55045, 66761, 66862, 77467, 81204, 82921, 92718, 104434]
        }

To compute your derivative (note here that data['y_p'] will be of size n-1 , therefore data['y_p'][i] is actually an approximation of the derivative at (data['x'][i] + data['x'][i+1]) / 2 ): 为了计算您的导数(请注意, data['y_p']的大小为n-1 ,因此data['y_p'][i]实际上是导数在(data['x'][i] + data['x'][i+1]) / 2的近似值(data['x'][i] + data['x'][i+1]) / 2 ):

import numpy as np

data['y_p'] = np.diff(data['y']) / np.diff(data['x'])
data['x_p'] = (np.array(data['x'])[:-1] + np.array(data['x'])[1:]) / 2

Then plot your results: 然后绘制结果:

import matplotlib.pyplot as plt

plt.figure(1)
plt.plot(data['x'], data['y'], 'r')
plt.plot(data['x_p'], data['y_p'], 'b')
plt.show()

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

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