Reputation:
I use plotly to plot my data by using this function:
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]
})
Upvotes: 2
Views: 22958
Reputation: 9019
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
):
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()
Upvotes: 5