treemap9.py 496 B

123456789101112
  1. import plotly.express as px
  2. import numpy as np
  3. df = px.data.gapminder().query("year == 2007")
  4. fig = px.treemap(df,
  5. path=[px.Constant("world"), 'continent', 'country'],
  6. values='pop',
  7. color='lifeExp',
  8. hover_data=['iso_alpha'],
  9. color_continuous_scale='RdBu',
  10. color_continuous_midpoint=np.average(df['lifeExp'],weights=df['pop']))
  11. fig.update_layout(margin = dict(t=50, l=25, r=25, b=25))
  12. fig.show()