I have the following dataframe:
date type value
1 2020-01-01 N 7956
2 2020-01-01 R 55709
3 2020-02-01 N 2513
4 2020-02-01 R 62325
5 2020-03-01 N 1419
6 2020-03-01 R 63745
7 2020-04-01 N 350
8 2020-04-01 R 65164
9 2020-05-01 N 11500
10 2020-05-01 R 65050
11 2020-06-01 N 7208
12 2020-06-01 R 74550
13 2020-07-01 N 2904
14 2020-07-01 R 81158
15 2020-08-01 N 11054
16 2020-08-01 R 80841
17 2020-09-01 N 7020
18 2020-09-01 R 91445
19 2020-10-01 N 25448
20 2020-10-01 R 97776
21 2020-11-01 N 8497
22 2020-11-01 R 122479
23 2020-12-01 N 11154
24 2020-12-01 R 129813
I'm building the visualization below with this dataframe. My code so far is:
fig = px.bar(df_vintage, x='date', y='value', color='type',
labels={'type': 'value'}, category_orders={"type": ["R", "N"]})
fig.update_layout(
title_text='Vintage Analysis',
template='seaborn',
margin=dict(l=50, r=50, t=50, b=50),
legend=dict(yanchor="top", y=0.98, xanchor="left", x=0.02),
)
fig.update_xaxes(
dtick="M1",
tickformat="%b\n%Y")
fig.show()
I'm trying to insert a line visualization, with the percentage change of the total value, from month-to-month (but without the using the make_subplots from Plotly). To create the vector from the percentage change:
pct_change = df_vintage.groupby('dates').sum().pct_change().reset_index()
I'm referring to the blue line I draw in the visualization. Any ideas? Thanks in advance.
CodePudding user response:
If you have to avoid using make_subplots
then you can draw the line using the