我正在尝试向一组子绘图(为简单起见,下面仅使用一个空绘图创建一个简单的可重复示例)添加一个交互式形状(圆形)。在绘图交互式参数中访问形状参数
以下代码的预期行为是能够使用下拉菜单在两个不同的圆圈之间切换。
import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools
# Create empty plot to put shapes into
scatter = go.Scatter()
fig = tools.make_subplots(cols=1)
fig.append_trace(scatter, 1, 1)
# Create two different shapes to select from
fig['layout']['shapes'].append(
{
'type': 'circle',
'xref': 'x', 'yref': 'y',
'x0': 0, 'y0': 0, 'x1': 1, 'y1': 1,
'visible':True
})
fig['layout']['shapes'].append(
{
'type': 'circle',
'xref': 'x', 'yref': 'y',
'x0': 0, 'y0': 0, 'x1': 0.5, 'y1': 0.5,
'visible':False
})
# This doesn't work
fig['layout']['updatemenus'] =
[{
x:-0.05, y:0.8,
buttons=[
{args:['layout.shapes.visible', [True, False]], label:'1', method:'restyle'},
{args:['layout.shapes.visible', [False, True]], label:'2', method:'restyle'}
]
}]
py.plot(fig, filename='shape_select')
我以为我的错误是,我指的是visible
参数以错误的方式,并应layout.shapes.visible
用别的东西来代替。
那么,在这种情况下,我该如何正确引用形状参数呢?
谢谢,预期最后两行正在努力!是的,我确实尝试了第一个选项的第一件事,也惊讶它没有工作... – sashkello
不知道如果错误或用户太愚蠢。 –
另一个愚蠢的问题:)如果我想传递几个参数呢?也就是说,通过一个下拉菜单可以更改散点图的形状和数据,我该怎么做?似乎很明显,但在例子中找不到它,'args = ['shapes',['],'visible',[True,False]]似乎只是打破了整个事物...我可以单独发布... – sashkello