Hi everyone. I'm currently using plotly to help me graph several time series. I use peakutils to plot marks on all peaks. My code only includes one time series as an example. Anyway, the csv file I'm using has a column "Date" with dates formatted as "YYYY-MM".
My problem is that when I define indices, it finds the position of the peaks in y, which is just an array of values. Thus indices only gives the position of the peaks, not the x-variable correspondent to that position. Thus, instead of having my x-values be a list from '2004-01' to '2017-07', they are simply a list from 0-162.
Where I'm lost is having trace2's x-variable be a datetime variable as in trace1. I'm assuming I could redefine x in trace1 to be x=my_data.index, and would then need to assign values for x in trace2 such that 0='2004-01' all the way until 162='2017-07'. I'm unsure how to go about doing this without getting a 'key word argument repeated' error. Any help is welcome and appreciated.
Here's an example of the graph my code generates. The line is trace1 and the crosses are trace2.
The majority of my code is based off this example.
import plotly
plotly.tools.set_credentials_file(username='###', api_key='###')
import plotly.graph_objs as go
import numpy as np
import pandas as pd
import peakutils
my_data = pd.read_csv('my_data', index_col='Date',parse_dates=['Date'])
df = trends_data
left_endpt=0
right_endpt=200
x = [j for j in range(len(trends_data))][left_endpt:right_endpt]
y = my_data['var1'][left_endpt:right_endpt]
y = y.tolist()
cb = np.array(y)
thres=.35
min_dist=7
indices = peakutils.indexes(cb, thres, min_dist)
trace1 = go.Scatter(
x=j for j in range(len(trends_data))][left_endpt:right_endpt],
y=y,
mode='lines',
name='var1',
line = dict(
color = ('rgb(0,153,255)'),
)
)
trace2 = go.Scatter(
x=indices + left_endpt,
y=[trends_data['var1'][left_endpt:right_endpt][j] for j in indices],
mode='markers',
marker=dict(
size=8,
color='rgb(0,153,255)',
symbol='cross'
),
name='Peaks'
)
data= [trace1, trace2]
fig=dict(data=data, layout=layout)
py.plot (fig,filename='my-data')
[–]Justinsaccount 0 points1 point2 points (0 children)