2016-12-30 24 views
0

我想每個插曲獨立的註釋對象在Plotly(Python)的關聯,這可怎麼辦呢?如何單獨標註每個副區在Plotly(Python)的

我試過

我設立這樣的情節:

from plotly import tools 
fig = tools.make_subplots(rows=2, cols=1) 
fig.append_trace(traces[0], 1, 1) 
fig.append_trace(traces[1], 2, 1) 

其中每個軌跡是這樣形成的:

import plotly.graph_objs as go 
traces[0] = go.Scatter(
      x=[1,2,3,4], 
      y=[4,4,2,1], 
      mode='markers' 
     ) 

我知道我可以訪問每個副區的x軸分別經由:

fig['layout']['xaxis1'].update(title='hello1') 
fig['layout']['xaxis2'].update(title='hello2') 

但我怎樣才能訪問每個子圖的註釋?我嘗試了「annotations1」和「annotation1」,但沒有運氣。我也試圖通過「佈局1」訪問插曲1的佈局,如:

fig['layout1'][...].update(...) 

這也不能工作。

回答

3

1)你可以通過設置xrefyref與副區軸線的id,如x1y1分配註釋到特定副區表示x軸和subplot1的Y軸,如從下面的例子,更上link

fig['layout'].update(
    annotations=[ 
    dict(
     x=2, y=2, # annotation point 
     xref='x1', 
     yref='y1', 
     text='dict Text', 
     showarrow=True, 
     arrowhead=7, 
     ax=10, 
     ay=70 
    ), 
    dict(
     ... 
     # if have multiple annotations 
    ) 
]) 
看出

2)你分配後,您可以打通

fig['layout']['annotations'] 

訪問註釋將返回字典的項目清單:

[{'xref': 'x2', 'arrowhead': 7, 'yref': 'y2', 'text': 'dict Text', 'ay': 40, 'ax': 10, 'y': -1.9491807521563174, 'x': 0.77334098360655923, 'showarrow': True}, {'xref': 'x2', 'arrowhead': 7, 'yref': 'y2', 'text': 'dict Text', 'ay': -40, 'ax': 10, 'y': -0.0041268527747384542, 'x': 1.1132422279202281, 'showarrow': True}] 

希望能幫助;)

相關問題