python - Plotly Dash - 在 dcc.graph 中向图形添加标题时出现语法错误
问题描述
刚刚浏览了 Dash 网站上的示例教程,我尝试修改示例代码,并在尝试为第二个 dcc.Graph 中的图形添加标题时遇到语法错误。
第二个 dcc.Graph 是我创建的。 代码调试器报告“标题”和“测试进度”之间的冒号是语法错误。我检查了所有的括号,它们都正确排列。请注意,我没有包含完整的源代码,因为只有 dcc.Graph 部分与错误相关。我的猜测是可能使用了错误类型的括号。但基于第一个 dcc.Graph,我认为情况并非如此。
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'},
],
'layout': {
'title': 'Dash Data Visualization'
}
}
),
dcc.Graph(id='plot1',
figure={
plotly_figure, 'layout' : {
'title': 'Test Progress'
}
}
)
附加信息:在 dcc.Graph 部分添加了与 plotly_figure 相关的实际数据行,并且不再出现语法错误。
plotly_figure = dict(data=[dict(x=[1,2,3], y=[2,4,8])])
dcc.Graph(id='plot1',
figure = {
'data': [
{dict(data=[dict(x=[1,2,3], y=[2,4,8])])},
],
'layout' : {
'title' : 'Test Progress'
}
}
)
问题的解决方案:plotly_fig 的正确语法如下:
plotly_fig = [dict(x=[1,2,3], y=[2,4,8])]
dcc.Graph(id='plot1',
figure={
plotly_fig, 'layout' : {
'title': 'Test Progress'
}
}
)
解决方案
推荐阅读
- linux - Linux 记录器的替代品
- oracle-cloud-infrastructure - 无法列出公共存储桶中的内容
- python - 在 NumPy 中向量化 2D 卷积
- docker - 与不同桥接网络中的多个 docker-compose.yml 通信
- markdown - 如何按顺序自动编号 MkDocs 图形
- java - Java固定线程池竞争条件?
- python-3.x - 如何使用 if 语句同时读取列表中的所有元素?
- python - 按 2 列分组并在 Pandas 中为每个组合打印数据
- ios - Apple 开发者注册错误:此时无法完成您在 Apple 开发者计划中的注册
- apache-spark - 在 Pyspark 中将月份名称转换为数字