Skip to content

Instantly share code, notes, and snippets.

@max-torch
Created May 21, 2021 11:05
Show Gist options
  • Save max-torch/e94d49282de0d46725059b59944f7946 to your computer and use it in GitHub Desktop.
Save max-torch/e94d49282de0d46725059b59944f7946 to your computer and use it in GitHub Desktop.
bssoupblog5
import os
if not os.path.exists("images"):
os.mkdir("images")
import plotly.express as px
import plotly.io as pio
pio.kaleido.scope.default_format = "png"
pio.kaleido.scope.default_width = "1024"
pio.kaleido.scope.default_height = "768"
resampled_df_y = df_no_refund.resample('Y', on='Date').sum().reset_index()
treemap1_df = resampled_df_y.copy()
treemap1_df['treeroot'] = 'Yearly Expense'
treemap1_df['Year'] = treemap1_df.Date.dt.year
fig = px.treemap(
treemap1_df,
path=['treeroot', 'Year'],
values = 'Total',
title = 'Distribution of Steam Spending by Year',
)
fig.update_traces(hovertemplate = 'Year: %{label}<br>Expense: %{value:,.2f}<br>Percent of Total: %{percentRoot:.2%}')
fig.update_traces(
marker_showscale=False,
texttemplate='Year: %{label}<br>Expense: %{value:,.2f}<br>Percent of Total: %{percentRoot:.2%}'
)
fig.update_layout(hoverlabel=dict(bgcolor="white"))
fig.show()
fig.write_image("images/fig1.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment