Python 有没有办法用绘图仪改变太阳爆发图中一层的厚度

Python 有没有办法用绘图仪改变太阳爆发图中一层的厚度,python,plotly,sunburst-diagram,Python,Plotly,Sunburst Diagram,我想在一张太阳爆发图中改变一层的厚度。我看了所有的例子,但没有找到任何好的解决办法 以下面的例子(来自上面的链接) 这可能吗?据我所知,这是不容易实现的。或中没有任何内容表明存在允许修改每个层比例的参数。不过,再深入一点也无妨 如果我们看下面的代码示例: import plotly.express as px data = dict( character=["Eve", "Cain", "Seth", "Enos&

我想在一张太阳爆发图中改变一层的厚度。我看了所有的例子,但没有找到任何好的解决办法

以下面的例子(来自上面的链接)


这可能吗?

据我所知,这是不容易实现的。或中没有任何内容表明存在允许修改每个层比例的参数。不过,再深入一点也无妨

如果我们看下面的代码示例:

import plotly.express as px
data = dict(
    character=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parent=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ],
    value=[10, 14, 12, 10, 2, 6, 6, 4, 4])

fig =px.sunburst(
    data,
    names='character',
    parents='parent',
    values='value'
) 
如果我们运行此Python代码,并键入
fig.layout.template.data
,我们可以看到用于生成sunburst图表的图表类型和相应参数:

layout.template.Data({
    'bar': [{'error_x': {'color': '#2a3f5f'},
             'error_y': {'color': '#2a3f5f'},
             'marker': {'line': {'color': '#E5ECF6', 'width': 0.5}},
             'type': 'bar'}],
    'barpolar': [{'marker': {'colorbar': {'len': 0.9, 'lenmode': 'fraction'}, 'line': {'color': '#E5ECF6', 'width': 0.5}},
                  'type': 'barpolar'}],
    'carpet': [{'aaxis': {'endlinecolor': '#2a3f5f',
                          'gridcolor': 'white',
                          'linecolor': 'white',
                          'minorgridcolor': 'white',
                          'startlinecolor': '#2a3f5f'},
                'baxis': {'endlinecolor': '#2a3f5f',
                          'gridcolor': 'white',
                          'linecolor': 'white',
                          'minorgridcolor': 'white',
                          'startlinecolor': '#2a3f5f'},
                'type': 'carpet'}],
    'choropleth': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'choropleth'}],
    'contour': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
                 'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'],
                                [0.2222222222222222, '#7201a8'],
                                [0.3333333333333333, '#9c179e'],
                                [0.4444444444444444, '#bd3786'],
                                [0.5555555555555556, '#d8576b'],
                                [0.6666666666666666, '#ed7953'],
                                [0.7777777777777778, '#fb9f3a'],
                                [0.8888888888888888, '#fdca26'], [1.0, '#f0f921']],
                 'type': 'contour'}],
    'contourcarpet': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'contourcarpet'}],
    'heatmap': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
                 'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'],
                                [0.2222222222222222, '#7201a8'],
                                [0.3333333333333333, '#9c179e'],
                                [0.4444444444444444, '#bd3786'],
                                [0.5555555555555556, '#d8576b'],
                                [0.6666666666666666, '#ed7953'],
                                [0.7777777777777778, '#fb9f3a'],
                                [0.8888888888888888, '#fdca26'], [1.0, '#f0f921']],
                 'type': 'heatmap'}],
    'heatmapgl': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
                   'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
                                  '#46039f'], [0.2222222222222222, '#7201a8'],
                                  [0.3333333333333333, '#9c179e'],
                                  [0.4444444444444444, '#bd3786'],
                                  [0.5555555555555556, '#d8576b'],
                                  [0.6666666666666666, '#ed7953'],
                                  [0.7777777777777778, '#fb9f3a'],
                                  [0.8888888888888888, '#fdca26'], [1.0,
                                  '#f0f921']],
                   'type': 'heatmapgl'}],
    'histogram': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'histogram'}],
    'histogram2d': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
                     'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
                                    '#46039f'], [0.2222222222222222, '#7201a8'],
                                    [0.3333333333333333, '#9c179e'],
                                    [0.4444444444444444, '#bd3786'],
                                    [0.5555555555555556, '#d8576b'],
                                    [0.6666666666666666, '#ed7953'],
                                    [0.7777777777777778, '#fb9f3a'],
                                    [0.8888888888888888, '#fdca26'], [1.0,
                                    '#f0f921']],
                     'type': 'histogram2d'}],
    'histogram2dcontour': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
                            'colorscale': [[0.0, '#0d0887'], [0.1111111111111111,
                                           '#46039f'], [0.2222222222222222,
                                           '#7201a8'], [0.3333333333333333,
                                           '#9c179e'], [0.4444444444444444,
                                           '#bd3786'], [0.5555555555555556,
                                           '#d8576b'], [0.6666666666666666,
                                           '#ed7953'], [0.7777777777777778,
                                           '#fb9f3a'], [0.8888888888888888,
                                           '#fdca26'], [1.0, '#f0f921']],
                            'type': 'histogram2dcontour'}],
    'mesh3d': [{'colorbar': {'outlinewidth': 0, 'ticks': ''}, 'type': 'mesh3d'}],
    'parcoords': [{'line': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'parcoords'}],
    'pie': [{'automargin': True, 'type': 'pie'}],
    'scatter': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatter'}],
    'scatter3d': [{'line': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
                   'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}},
                   'type': 'scatter3d'}],
    'scattercarpet': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattercarpet'}],
    'scattergeo': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattergeo'}],
    'scattergl': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattergl'}],
    'scattermapbox': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scattermapbox'}],
    'scatterpolar': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterpolar'}],
    'scatterpolargl': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterpolargl'}],
    'scatterternary': [{'marker': {'colorbar': {'outlinewidth': 0, 'ticks': ''}}, 'type': 'scatterternary'}],
    'surface': [{'colorbar': {'outlinewidth': 0, 'ticks': ''},
                 'colorscale': [[0.0, '#0d0887'], [0.1111111111111111, '#46039f'],
                                [0.2222222222222222, '#7201a8'],
                                [0.3333333333333333, '#9c179e'],
                                [0.4444444444444444, '#bd3786'],
                                [0.5555555555555556, '#d8576b'],
                                [0.6666666666666666, '#ed7953'],
                                [0.7777777777777778, '#fb9f3a'],
                                [0.8888888888888888, '#fdca26'], [1.0, '#f0f921']],
                 'type': 'surface'}],
    'table': [{'cells': {'fill': {'color': '#EBF0F8'}, 'line': {'color': 'white'}},
               'header': {'fill': {'color': '#C8D4E3'}, 'line': {'color': 'white'}},
               'type': 'table'}]
这有点凌乱,但据我所知,太阳爆发图或多或少是使用各种其他图表绘制的,包括
Barpolar
pie
graph\u对象

从Plotly中,Barpolar graph_对象如下所示:

可以指定每个条形的半径,但默认情况下,它们都将从原点向外辐射。但是,如果你真的想创建层厚不均匀的太阳暴日图,并且你愿意努力工作,你可以尝试自己在条形图的顶部构建它:我的建议是将彩色条覆盖在白色条上,并测试每个条的不同半径。以下是一个您可以实际实现的示例:

import plotly.graph_objects as go

fig = go.Figure()

## create bars of larger radius beneath
fig.add_trace(go.Barpolar(
    r=[5, 5],
    theta=[67.5, 180],
    width=[135, 90],
    marker_color=["salmon","yellow"],
    marker_line_color="white",
    marker_line_width=2,
    opacity=1
    )
)

fig.add_trace(go.Barpolar(
    r=[2, 2],
    theta=[67.5, 180],
    width=[135, 90],
    marker_color=["blue","green"],
    marker_line_color="white",
    marker_line_width=2,
    opacity=1
    )
)

## overlay a bar that removes the central circle
fig.add_trace(go.Barpolar(
    r=[1],
    theta=[0],
    width=[360],
    marker_color=["white"],
    marker_line_color="white",
    marker_line_width=2,
    opacity=1
    )
)

fig.update_layout(
    template=None,
    polar = dict(
        radialaxis = dict(range=[0, 6], showticklabels=False, ticks=''),
        angularaxis = dict(showticklabels=False, ticks='')
    )
)

fig.show()

然后,需要为名称和悬停模板中的值添加注释。你基本上是从头开始构建图表,所以我承认这将是一个艰苦的过程

注意:任何比我有更丰富的绘图经验的人,如果我在这方面有错误,请纠正我,如果每个层的厚度确实可以由Sunburst graph_对象中的参数控制

import plotly.graph_objects as go

fig = go.Figure()

## create bars of larger radius beneath
fig.add_trace(go.Barpolar(
    r=[5, 5],
    theta=[67.5, 180],
    width=[135, 90],
    marker_color=["salmon","yellow"],
    marker_line_color="white",
    marker_line_width=2,
    opacity=1
    )
)

fig.add_trace(go.Barpolar(
    r=[2, 2],
    theta=[67.5, 180],
    width=[135, 90],
    marker_color=["blue","green"],
    marker_line_color="white",
    marker_line_width=2,
    opacity=1
    )
)

## overlay a bar that removes the central circle
fig.add_trace(go.Barpolar(
    r=[1],
    theta=[0],
    width=[360],
    marker_color=["white"],
    marker_line_color="white",
    marker_line_width=2,
    opacity=1
    )
)

fig.update_layout(
    template=None,
    polar = dict(
        radialaxis = dict(range=[0, 6], showticklabels=False, ticks=''),
        angularaxis = dict(showticklabels=False, ticks='')
    )
)

fig.show()