为什么 plotly 的配置在破折号中不起作用?
Why doesn't the config for plotly doesn't work in dash?
当我使用 fig.show
时,模式栏按钮会显示出来,但是当我尝试对破折号执行相同操作时,它不起作用。我尝试了很多选择,但似乎都行不通。文档也不完整。顺便说一句,这些是内置按钮,不是自定义的。
我在教程中看到这个:
fig.show(config={'modeBarButtonsToAdd':['drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape'
]})
然后,我尝试用破折号而不是 fig.show
来代替它,但是行不通!
app.layout = html.Div([
dcc.Graph(
id='mainPlot',
figure=fig,
config={'modeBarButtonsToAdd':['drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape'
]}
)
])
这是 MWE:我想通过 app.layout
而不是 fig.show
将 config
与 modeBarButtonsToAdd
传递到 config
。它适用于 fig.show
,因为按钮是内置的,但不适用于 app.layout
配置传递,因为我收到错误消息,指出按钮需要用名称、点击功能等定义,并且正在被视为自定义按钮,而不是启用内置按钮。
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(children=[
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'
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True)
安装最新版本的 dash 应该可以解决您的问题。
当我使用 fig.show
时,模式栏按钮会显示出来,但是当我尝试对破折号执行相同操作时,它不起作用。我尝试了很多选择,但似乎都行不通。文档也不完整。顺便说一句,这些是内置按钮,不是自定义的。
我在教程中看到这个:
fig.show(config={'modeBarButtonsToAdd':['drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape'
]})
然后,我尝试用破折号而不是 fig.show
来代替它,但是行不通!
app.layout = html.Div([
dcc.Graph(
id='mainPlot',
figure=fig,
config={'modeBarButtonsToAdd':['drawline',
'drawopenpath',
'drawclosedpath',
'drawcircle',
'drawrect',
'eraseshape'
]}
)
])
这是 MWE:我想通过 app.layout
而不是 fig.show
将 config
与 modeBarButtonsToAdd
传递到 config
。它适用于 fig.show
,因为按钮是内置的,但不适用于 app.layout
配置传递,因为我收到错误消息,指出按钮需要用名称、点击功能等定义,并且正在被视为自定义按钮,而不是启用内置按钮。
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(children=[
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'
}
}
)
])
if __name__ == '__main__':
app.run_server(debug=True)
安装最新版本的 dash 应该可以解决您的问题。