简体   繁体   English

如何更改每个圆形扇区的colors? plotly

[英]how to change the colors of each circular sector? plotly

[enter image description here] [在此处输入图像描述]

1

how can i change the colors of each sector?如何更改每个扇区的 colors?

Also, how can I put a caption pair for each line (pair of circles)?另外,我怎样才能为每一行(一对圆圈)放置一个标题对?

The method of changing the color of each pie chart is possible by specifying a color for each marker.通过为每个标记指定颜色,可以更改每个饼图的颜色。 Since no data is presented, I have edited the example in the reference to make the graph suitable for your purposes.由于没有提供数据,我已经编辑了参考中的示例,以使图表适合您的目的。 The colors were determined by selecting two of the 24 colors in the default color map, combining them, and then extracting four similar colors from the list. The colors were determined by selecting two of the 24 colors in the default color map, combining them, and then extracting four similar colors from the list. If you already have a set of colors in mind, you can specify the number of colors you need in a list, for example.如果您已经有一组 colors,您可以在列表中指定您需要的 colors 的数量,例如。 There is no way to add line labels, so I used string annotations.没有办法添加线标签,所以我使用了字符串注释。

from plotly.subplots import make_subplots
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
import itertools
import random

#colors = ['gold', 'mediumturquoise', 'darkorange', 'lightgreen']
colors = px.colors.qualitative.Dark24 + px.colors.qualitative.Light24

fig = make_subplots(rows=4, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}],
                                           [{'type':'domain'}, {'type':'domain'}],
                                           [{'type':'domain'}, {'type':'domain'}],
                                           [{'type':'domain'}, {'type':'domain'}],
                                          ])

for r,c in itertools.product([1,2,3,4],[1,2]):
    fig.add_trace(go.Pie(
        labels=['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen'],
        values=np.random.randint(500,5000,4),
        marker=dict(colors=random.sample(colors,4), line=dict(color='#000000', width=2)
                   )), row=r, col=c
                 )
    fig.update_traces(hoverinfo='label+percent', textinfo='value', textfont_size=12, showlegend=False)

for i in range(4):
    fig.add_annotation(text='Row{}'.format(i+1), textangle=-90, font=dict(size=16), x=-0.1, y=0.05+0.31*i, xref='paper', yref='paper', showarrow=False)

fig.update_layout(autosize=True,
                  height=600,
                  width=800)
fig.show()

在此处输入图像描述

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

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