[英]plotly dash display graph_objects pie chart inside html elemet
[英]problem with inserting data into the bar chart plotly graph_objects
所以我试图将列表(内部,外部..)添加到条形图中,但数据进入“内部”一列
它应该与此类似
这是整个 df 和我所做的工作
社会提到了最小可复制的例子,那么你必须考虑这意味着什么。 在您的情况下,问题是:
plotly.graph_objects
go.Bar()
需要的数据到底是什么。 ( status
, escalation
) 由以上问题推断,
a) 你如何在 StackOverflow 中为演示获取最小部分的数据?
b) 如何从您的df
准备数据并将它们转换为 plot。
准备我们想要的数据 plot:
import random
import pandas as pd
import plotly.graph_objects as go
random.seed(42)
sample_quntity = 50
status = [random.choice(['Not Done','Something Else','Done']) for i in range(sample_quntity)]
escalation = [random.choice(['Internal','External','Unspecified']) for i in range(sample_quntity)]
df = pd.DataFrame({
'status':status,
'escalation':escalation
})
df
###
status escalation
0 Done Unspecified
1 Not Done External
2 Not Done Internal
3 Done Unspecified
4 Something Else External
5 Not Done Unspecified
⋮ ⋮ ⋮
43 Something Else Unspecified
44 Not Done Unspecified
45 Not Done Internal
46 Something Else Internal
47 Not Done External
48 Something Else External
49 Something Else External
Plot:
# plot bar chart grouping with status and escalation and color by status
group_list = df['escalation'].unique()
palette = {"Not Done": "#d89a9e","Something Else":"#e0c1b3", "Done": "#aeb4a9"}
fig = go.Figure(data=[
go.Bar(name='Not Done',
x=group_list,
y=df[df['status'] == 'Not Done'].groupby('escalation').size(),
marker_color=palette['Not Done']),
go.Bar(name='Something Else',
x=group_list,
y=df[df['status'] == 'Something Else'].groupby('escalation').size(),
marker_color=palette['Something Else']),
go.Bar(name='Done',
x=group_list,
y=df[df['status'] == 'Done'].groupby('escalation').size(),
marker_color=palette['Done'])])
fig.update_layout(title='Group by Escalation, Color by Status', barmode='stack')
fig.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.