如何在px.treemap中的textemplate中显示用于颜色的值
我正在使用Plotly Treemap进行第一次工作。我想显示用于块中颜色的值。
使用 this 答案,我能够创建custy> custydata
,但是treemap渲染值,但是,值在某些情况下显示不同记录的“增长”值的顺序与数据框架的顺序不同,它显示了“增长”值。它也不是偏离的。
示例数据:
Type,Stock,Holding,Growth
Equities,Sasol,500,118.06
ETFs,SATRIX Top 40,500,12.99
代码:
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()
渲染:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
阅读 this ,我能够打印无花果的数据,其中包括:
然后我可以使用以下方式访问值:
现在可以使用。
[因为我真的很挣扎,所以我决定发布答案,而不是删除问题,以防将来有人发现有用。]
Having read this, I was able to print the fig's data, which included:
So I could then access the values with:
And now it works.
[Because I really struggled with this, I decided to post the answer instead of deleting the question in case someone else in the future finds ity useful.]