I'm trying to plot my data in a comparative timeseries, however, I keep getting plots like this:
right now my data is formatted in a pandas DataFrame as so:
| | Date | Name1 | Name2 | Name3 |
| 0 | Timestamp('2005-08-06 00:00:00') | 1.5 | NaN | 3 |
| 1 | Timestamp('2003-09-07 00:00:00') | NaN | 1.3 | 2 |
| 2 | Timestamp('2002-10-02 00:00:00') | 1.6 | NaN | NaN |
| 3 | Timestamp('1996-11-02 00:00:00') | 1.6 | 1 | NaN |
| 4 | Timestamp('2005-10-02 00:00:00') | NaN | NaN | 1 |
and my process of plotting it goes as such:
def order_names(d):
d_ret = dict()
for i in d.keys():
x_coordinates = d[i].keys()
y_coordinates = d[i].values()
x,y = zip(*sorted(zip(x_coordinates, y_coordinates)))
d_star = {xi : yi for xi, yi in zip(x,y)}
d_ret[i] = d_star
return d_ret
d = get_data() #d = {name : {datetime.datetime : value...} ...}
d = order_data(d)
df = pd.DataFrame(d)
df.reset_index(inplace = True)
df.rename(columns={"index": "date"},inplace = True)
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Dropdown(
id='name',
options=[{"label": x, "value": x}
for x in df.columns[1:]],
multi=True,
value='Name1',
),
dcc.Graph(id="name-chart"),
])
@app.callback(
Output("name-chart", "figure"),
[Input("name", "value")])
def display_time_series(name):
fig = px.line(df, x='date', y=name, title = "Value vs. Time")
return fig
And I cannot figure out why dash/plotly is displaying the top graph out of order.
tl;dr: I'm trying to plot multiple timeseries which don't may or may not have matching dates