1 回答
TA贡献1810条经验 获得超4个赞
我不确定这是否是由于字幕设置引起的,但是add_annotation()是正确的,update(annotations=[]可能已被函数覆盖以更新已设置的注释。
import plotly.graph_objects as go
import numpy as np
from plotly.subplots import make_subplots
from math import exp
fig = make_subplots(2, 1, subplot_titles=('Activation', 'Prediction errors - Model, ALO and RND'))
x = np.linspace(0, 10, 100)
y = np.array(list(map(lambda x: 1 / (1 + exp(-0.1 * x + 5)), x)))
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'\N{Greek Small Letter Sigma}(x)',
showlegend=True
),
row=1,
col=1
)
fig['layout']['xaxis'].update(title_text='x')
for i in range(4):
x = np.where(np.random.randint(0, 2, 100)==1)[0]
fig.add_trace(
go.Scatter(
x=x,
y=np.zeros_like(x) + i,
name=f'Plot {i}',
mode='markers',
marker=dict(
symbol='circle-open',
color='green',
size=5
),
showlegend=True
),
row=2,
col=1
)
fig['layout']['xaxis2'].update(title_text='active users', autorange=True)
fig['layout']['yaxis2'].update(title_text='active users', visible=True, range=[-1,4])
fig.add_annotation(
dict(x=0, y=3.125, xref='x2', yref='y2', text='RND', showarrow=True, font=dict(size=10, color='black'))
)
fig.add_annotation(
dict(x=0, y=2.125, xref='x2', yref='y2', text='ALO', showarrow=True, font=dict(size=10, color='red'))
)
fig.add_annotation(
dict(x=0, y=1.125, xref='x2', yref='y2', text='Model', showarrow=True, font=dict(size=10, color='Blue'))
)
fig.add_annotation(
dict(x=0, y=0.125, xref='x2', yref='y2', text='True activity', showarrow=True, font=dict(size=10, color='green'))
)
fig.show()
添加回答
举报