我有以下数据框架:
- dcc.Dropdown选择问题在页面上 -
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
最终结果需要有三组图表。每组由两个堆叠并排放置的条形图组成。
结果如下:
图1由两个并排的条组成:
bar 1 =堆叠作业(高度= 9,堆栈由2xCSM,3xSA,2xMIA,2xADCS组成)
bar2 =按角色分类问题。例如如果在下拉列表中选择了“预算削减”问题,则此图形将为height = 3,堆栈由2xCSM,1xADCS组成。
当您从下拉列表中选择问题时,栏2需要更新。因此,如果我现在选择“缺乏监督”,则第2栏的高度为1,由作业1 x SA堆叠。
图2和图3将与上述相同,但分别用于任期和位置而不是工作。因此,在上述实例中作为Job的所有实例中,堆栈将是Tenure / Location。
说实话,即使有人可以告诉我如何做第一张图表,我也可以复制图表2和3的代码。我希望这是有道理的。
这是我得到的输出。我基本上希望同一轴上的这两个条不像这里那样分开(忽略高度值,因为我的df大于我在这里给出的值)。
多谢你们。
这是一个简单的工作示例,改编自
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)
它应该输出像,