Please see the plot:
The code:
data_list = []
mvc_df = local_df[local_df[1] == valuation[0]].sort_values(0)
mvc_df.set_index(0, inplace=True)
mvc_df = mvc_df.groupby([0])[2].sum()
mvc_df = mvc_df - mvc_df.shift(1)
data_list.append(go.Bar(x=list(mvc_df.index),
y=mvc_df,
name='Change',
marker=dict(
color='rgb(158,202,225)',
line=dict(
color='rgb(8,48,107)',
width=1.5
)
),
opacity=.6))
average_change = mvc_df.sum()/mvc_df.count()
mean_list = []
[mean_list.append(average_change) for x in range(mvc_df.count() + 1)]
data_list.append(go.Scatter(x=list(mvc_df.index),
y=mean_list,
name='Avg=${}M'.format(round(average_change/1000000,2)),
mode='lines',
line=dict(color='black',
dash='dash'),
opacity=.2))
mv_df = local_df[local_df[1] == valuation[0]].sort_values(0)
mv_df.set_index(0, inplace=True)
mv_df = mv_df.groupby([0])[2].sum()
data_list.append(go.Scatter(x=list(mv_df.index),
y=mv_df,
name='Value',
yaxis='y2',
mode='markers',
marker=dict(size=16,
color='green')))
data_list.append(go.Scatter(x=list(mv_df.index),
y=mv_df,
name='Value',
yaxis='y2',
mode='lines',
marker=dict(color='grey')))
plotly.offline.plot(figure_or_data=
{
'data': data_list,
'layout': go.Layout(title='Market Value',
showlegend=True,
legend=dict(x=.8,
y=.98),
xaxis=dict(
showticklabels=True,
tickangle=90,
nticks=(datetime.now() - datetime.strptime(start_date,'%Y-%m-%d')).days),
yaxis=dict(
title='Market Value Change',
titlefont=dict(color='rgb(8,48,107)'),
tickfont=dict(color='rgb(158,202,225)')
),
yaxis2=dict(
title='Market Value',
titlefont=dict(color='grey'),
tickfont=dict(color='green'),
side='right',
overlaying='y'
)
)
},
image='png',
image_filename=file_name,
filename='{}\{}.html'.format(directory, file_name),
auto_open=False
)