gpt4 book ai didi

python - Plotly-Dash 堆叠条形图并排响应下拉列表

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:18 25 4
gpt4 key购买 nike

我有以下数据框:

-- dcc.用于选择问题的下拉菜单位于页面的此处--

Job  Tenure  Location  Topic
CSM 3-5 England Budget cuts
CSM 6-10 Scotland Budget cuts
SA 0-2 India Time consuming demands
SA 3-5 England Lack of oversight
SA 6-10 Germany Lack of support
MIA 11-15 India Lack of support
ADCS 20+ England Bureaucracy
MIA 16-20 Ireland Bureaucracy
ADCS 20+ USA Budget cuts

最终的结果需要有三组图表。每组包含两个并排堆叠的条形图。

结果如下:

图一由两个并排的条组成:

bar 1 = stacked jobs (height=9, stack consists of 2xCSM, 3xSA, 2xMIA, 2xADCS)

bar2 = 按角色分割的问题。例如如果在下拉列表中选择了“预算削减”问题,则此图的高度将为 3,堆栈由 2xCSM、1xADCS 组成。

当您从下拉列表中选择一个问题时,第 2 栏需要更新。因此,如果我现在选择问题“缺乏监督”,则条形图 2 的高度将为 1,由作业 1 x SA 堆叠。

图 2 和图 3 与上图相同,但分别针对 Tenure 和 Location 而不是 job。因此,在上述实例中,堆栈在所有实例中都是 Tenure/Location。

老实说,即使有人可以告诉我如何制作第一个图表,我也可以复制图表 2 和 3 的代码。我希望这是有道理的。

这是我得到的输出。我基本上希望同一轴上的这两个条形图不像这里那样分开(忽略高度值,因为我的 df 大于我在这里给出的值)。

enter image description here

谢谢大家。

最佳答案

这是一个简单的工作示例,改编自

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
html.H1(children='Hello Dash'),

html.Div(children='''
Dash: A web application framework for Python.
'''),

dcc.Graph(
id='example-graph',
figure={
'data': [
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
{'x': [1, 2, 3], 'y': [5, 2, 6], 'type': 'bar', 'name': 'SF', 'xaxis': 'x2',},
{'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': u'Montréal', 'yaxis': 'y2',},
],
'layout': {
'title': 'Dash Data Visualization',
'xaxis': {'domain':[0, 0.5]},
'xaxis2': {'domain':[0.6, 1]},
'yaxis2': {'anchor': 'x2'}
}
}
)
])

if __name__ == '__main__':
app.run_server(debug=True)

它应该输出类似的东西,

enter image description here

关于python - Plotly-Dash 堆叠条形图并排响应下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55264554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com