简体   繁体   English

Plotly 的树状图和森伯斯特显示错误的尺寸

[英]Plotly's treemap and sunburst show wrong sizes

I am trying to use plotly's sunburst and treemap to visualize data.我正在尝试使用 plotly 的森伯斯特和树状图来可视化数据。 However, I discovered that the child nodes show wrong size compared to their parents, that is, the sum of children's size does not cover that of the parents:但是,我发现子节点与其父节点相比显示错误的大小,即子节点大小的总和不包括父节点的大小:

import plotly.graph_objects as go

fig =go.Figure(go.Treemap(
    labels= ["i_1", "i_2", "c_a", "i_3", "c_b"],
    parents= ["c_a", "c_a", "", "c_b", ""], 
    values= [3, 2, 5, 2, 2],
))

fig.show()

The output:输出:

树状图输出

As you can see, in the raw data, i_1 and i_2 together have a sum of 5, equal their parent c_a's 5. But in the graph, the "c_a" block is not filled up by i_1 and i_2 together.如您所见,在原始数据中,i_1 和 i_2 的总和为 5,等于它们的父 c_a 的 5。但在图中,“c_a”块没有被 i_1 和 i_2 一起填充。 Same goes for i_3 and c_b. i_3 和 c_b 也是如此。 Even though the mouseover popups show the correct values.即使鼠标悬停弹出窗口显示正确的值。

Same goes for the sunburst visualization:旭日形可视化也是如此:

import plotly.graph_objects as go

fig =go.Figure(go.Sunburst(
    labels= ["i_1", "i_2", "c_a", "i_3", "c_b"],
    parents= ["c_a", "c_a", "", "c_b", ""], 
    values= [3, 2, 5, 2, 2],
))

fig.show()

旭日图

Again, i_1 and i_2 together do not cover the whole scope of c_a.同样,i_1 和 i_2 一起不涵盖 c_a 的整个范围。

Are the settings to force plotly to truthfully represent the proportions of the father-child sizes.是否设置强制情节真实地表示父子大小的比例。 To be honest, the current representation is not usable for my purpose.老实说,当前的表示不能用于我的目的。

Yes, set branchvalues="total" .是的,设置branchvalues="total" The default is "remainder" which adds the value to the sum of the children, as you see in your figures.默认值为"remainder" ,它将值添加到子项的总和中,如您在图中所见。 You could also leave that setting alone and set the value for all non-leaf nodes to 0.您也可以不理会该设置,并将所有非叶节点的值设置为 0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM