Skip to content

Instantly share code, notes, and snippets.

@stanlee321
Last active September 14, 2020 15:12
Show Gist options
  • Save stanlee321/6ce1c1785ac344feffb6b9f1837d33cc to your computer and use it in GitHub Desktop.
Save stanlee321/6ce1c1785ac344feffb6b9f1837d33cc to your computer and use it in GitHub Desktop.
treemaps python
def plot_treemap(df, values="count", columns = [], title='Proyectos en curso por Departamento', width=1200, height=600):
fig1 = px.treemap(df.sort_values(by=values, ascending=False).reset_index(drop=True),
path=columns, values=values, title=title,
color_discrete_sequence = px.colors.qualitative.Prism, width=width,height=height, maxdepth = 4, )
fig1.data[0].textinfo = 'label+text+value+percent entry'
py.offline.iplot(fig1)
return fig1
# Use
fig1 = plot_treemap(dfs,values="Value", columns =["Name", "Departamento"], title="<b>Proyectos en curso:</b> Ministerio -> Departamento")
fig1.write_html(f"fig1_treeplot_Departamentos_{now}.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment