亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

文本位置不顯示在情節上

文本位置不顯示在情節上

慕標琳琳 2022-07-26 15:40:50
我正在嘗試使用 plotly 繪制我的神經網絡的訓練和測試集的準確性。我還想添加一個帶有文本的標記,該文本說明每個時間的最大值是什么時候,但還顯示一個說明該值是什么的文本。我嘗試在這個例子中做類似的事情。這是我的mcve:import plotly.graph_objects as godata = {    'test acc':  [1, 2, 3, 4, 5, 6, 7, 9, 10],    'train acc': [3, 5, 5, 6, 7, 8, 9, 10, 8]}fig = go.Figure()color_train = 'rgb(255, 0, 0)'color_test = 'rgb(0, 255, 0)'assert len(data["train acc"]) == len(data["test acc"])x = list(range(len(data["train acc"])))fig.add_trace(go.Scatter(x=x,                         y=data["train acc"],                         mode='lines',                         name='train acc',                         line_color=color_train))fig.add_trace(go.Scatter(x=x,                         y=data["test acc"],                         mode='lines',                         name='test acc',                         line_color=color_test))# Max pointstrain_max = max(data["train acc"])test_max = max(data["test acc"])# ATTENTION! this will only give you first occurrencetrain_max_index = data["train acc"].index(train_max)test_max_index = data["test acc"].index(test_max)fig.add_trace(go.Scatter(x=[train_max_index],                         y=[train_max],                         mode='markers',                         name='max value train',                         text=['{}%'.format(int(train_max * 100))],                         textposition="top center",                         marker_color=color_train))fig.add_trace(go.Scatter(x=[test_max_index],                         y=[test_max],                         mode='markers',                         name='max value test',                         text=['{}%'.format(int(test_max*100))],                         textposition="top center",                         marker_color=color_test))fig.update_layout(title='Train vs Test accuracy',                  xaxis_title='epochs',                  yaxis_title='accuracy (%)'                  )fig.show()但是,我的輸出火力如下:如您所見,該值沒有像我找到的示例那樣顯示。我怎樣才能讓它出現?
查看完整描述

1 回答

?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

如果您只想突出顯示某些特定值,請使用add_annotation(). 在您的情況下,只需找到您想要關注的 X 的最大和最小 Y。缺少您身邊的數據樣本,以下是我使用通用數據樣本的方法:

陰謀:

http://img1.sycdn.imooc.com//62df9ab60001049416340611.jpg

代碼:


import plotly.graph_objects as go

import plotly.io as pio


pio.renderers.default='browser'


fig = go.Figure()


xVars1=[0, 1, 2, 3, 4, 5, 6, 7, 8]

yVars1=[0, 1, 3, 2, 4, 3, 4, 6, 5]



xVars2=[0, 1, 2, 3, 4, 5, 6, 7, 8]

yVars2=[0, 4, 5, 1, 2, 2, 3, 4, 2]


fig.add_trace(go.Scatter(

    x=xVars1,

    y=yVars1

))



fig.add_trace(go.Scatter(

    x=xVars2,

    y=yVars2

))


fig.add_annotation(

            x=yVars1.index(max(yVars1)),

            y=max(yVars1),

            text="yVars1 max")

fig.add_annotation(

            x=yVars2.index(max(yVars2)),

            y=max(yVars2),

            text="yVars2 max")

fig.update_annotations(dict(

            xref="x",

            yref="y",

            showarrow=True,

            arrowhead=7,

            ax=0,

            ay=-40

))


fig.update_layout(showlegend=False)


fig.show()


查看完整回答
反對 回復 2022-07-26
  • 1 回答
  • 0 關注
  • 93 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號