没有直接的方法,但你可以添加
shapes
在你的
layout
假设误差是一个二维列表:
errors = {'x': [[0.1, 0.4],
[0.2, 0.3],
[0.3, 0.2],
[0.4, 0.1],
[0.45, 0.05]
],
'y': [[0.4, 0.1],
[0.3, 0.2],
[0.2, 0.3],
[0.1, 0.4],
[0.05, 0.45]]}
现在我们创建一个矩形
shape
对于每个错误:
shapes = list()
for i in range(len(errors['x'])):
shapes.append({'x0': points['x'][i] - errors['x'][i][0],
'y0': points['y'][i] - errors['y'][i][0],
'x1': points['x'][i] + errors['x'][i][1],
'y1': points['y'][i] + errors['y'][i][1],
'fillcolor': 'rgb(160, 0, 0)',
'layer': 'below',
'line': {'width': 0}
})
layout = plotly.graph_objs.Layout(shapes=shapes)
非对称误差条是通过
'symmetric': False
points = {'x': [0, 1, 2, 3, 4],
'y': [0, 2, 4, 1, 3]}
errors = {'x': [[0.1, 0.4],
[0.2, 0.3],
[0.3, 0.2],
[0.4, 0.1],
[0.45, 0.05]
],
'y': [[0.4, 0.1],
[0.3, 0.2],
[0.2, 0.3],
[0.1, 0.4],
[0.05, 0.45]]}
scatter = plotly.graph_objs.Scatter(x=points['x'],
y=points['y'],
error_x={'type': 'data',
'array': [e[1] for e in errors['x']],
'arrayminus': [e[0] for e in errors['x']],
'symmetric': False
},
error_y={'type': 'data',
'array': [e[1] for e in errors['y']],
'arrayminus': [e[0] for e in errors['y']],
'symmetric': False
},
mode='markers')
shapes = list()
for i in range(len(errors['x'])):
shapes.append({'x0': points['x'][i] - errors['x'][i][0],
'y0': points['y'][i] - errors['y'][i][0],
'x1': points['x'][i] + errors['x'][i][1],
'y1': points['y'][i] + errors['y'][i][1],
'fillcolor': 'rgb(160, 0, 0)',
'layer': 'below',
'line': {'width': 0}
})
layout = plotly.graph_objs.Layout(shapes=shapes)
data = plotly.graph_objs.Data([scatter], error_x=[e[0] for e in errors['x']])
fig = plotly.graph_objs.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)