I'm doing my first work with a Plotly Treemap. I want to show the values used for the colors in the blocks.
Using this answer, I was able to create customdata
, and the treemap renders however, the values are not in the same order as the dataframe and it shows the 'Growth' value for a different record in some cases. It is also not off-by-one.
Sample data:
Type,Stock,Holding,Growth
Equities,Sasol,500,118.06
ETFs,SATRIX Top 40,500,12.99
Code:
shares_data = pd.read_csv("stocks.csv", index_col=False)
fig = px.treemap(shares_data,
path=['Type', 'Stock'],
values='Holding',
color='Growth',
color_continuous_scale=[(0, "red"), (0.05, "yellow"), (1, "green")],
)
fig.data[0].customdata = shares_data.Growth
fig.data[0].texttemplate = "<b>%{label}</b><br>Holding: R%{value}<br>Growth: %{customdata:.2f}%<br>"
fig.show()
Rendered: