I'd like to plot time series simulation data as a mean with confidence intervals and compare multiple scenarios.
Using the pandas groupby()
and agg()
functions a calculate the mean and confidence interval (upper and lower limit) see sample data (the actual data can be retrieved from my github.
Edit: I added the raw data to the and the code (as a jupyter notebook) to the git
Plotting this data for one specific parameter combination (selecting data via df = df.loc[(slice(None),1, True)]
) seams simple enough:
myFig = go.Figure([
go.Scatter(
name='Mittelwert',
#x=df['tick'],
y=df['mean'],
mode='lines',
line=dict(color='rgb(31, 119, 255)'),
),
go.Scatter(
name='Konfidenzintervall',
#x=df['tick'],
y=df['ci95_hi'],
mode='lines',
marker=dict(color="#644"),
line=dict(width=0),
showlegend=True
),
go.Scatter(
name='Konfidenzintervall',
#x=df['tick'],
y=df['ci95_lo'],
marker=dict(color="#448"),
line=dict(width=0),
mode='lines',
fillcolor='rgba(130, 68, 68, 0.5)',
fill='tonexty',
showlegend=True
)
])
myFig.update_layout(
xaxis_title='X Achse',
yaxis_title='Y Achse',
title='Continuous, variable value error bars',
hovermode="x"
)
myFig.show()
This code gives me the that beautiful plot. The issue is a do not know how to properly plot the grouped data. When I don't select a subset all data is plotted at once.
Therefore i tried to use color
, facet_col
and facet_row
which I could get working using
px.line(reset_df, x = "tick", y="mean", color="first_factor",facet_col="second_factor")
(Since plotly apparently can't handle MultiIndex Dataframe i used reset_index()
to get a DataFrame with a 'RangeIndex' first). The issue is with the latter approach I'm now missing the confidence interval and don't know how to add it (c.f. this plot).
How can I have both the ci and the grouped data within one plot? If this is not possible with pandas is it with bokeh? Thank you very much