plotly treemap

plotly treemap

タグ visualizations


概要

  • 株価の可視化などに使用されるtreemap

サンプルコード

  • 人口と平均寿命のデータを使用してtreemapを作成する
import plotly.io as pio
pio.renderers.default = 'iframe'  # または 'jupyterlab', 'notebook', 'browser' に変更

import plotly.express as px
import numpy as np

df = px.data.gapminder().query("year == 2007")
fig = px.treemap(df, path=[px.Constant("world"), 'continent', 'country'], 
                  values='pop',
                  color='lifeExp', 
                  hover_data=['iso_alpha'],
                  color_continuous_scale='RdBu',
                  color_continuous_midpoint=np.average(df['lifeExp'], weights=df['pop']))
fig.update_layout(margin = dict(t=5, l=5, r=5, b=5))
fig.show()