Plotly-legends

提供:Dev Guides
移動先:案内検索

Plotly-伝説

デフォルトでは、複数のトレースを持つPlotlyチャートには、凡例が自動的に表示されます。 トレースが1つしかない場合は、自動的に表示されません。 表示するには、レイアウトオブジェクトの showlegend パラメータをTrueに設定します。

layout = go.Layoyt(showlegend = True)

凡例のデフォルトのラベルは、トレースオブジェクト名です。 凡例ラベルを設定するには、トレースの名前プロパティを明示的に設定します。

次の例では、nameプロパティを持つ2つの散布図がプロットされています。

import numpy as np
import math #needed for definition of pi

xpoints = np.arange(0, math.pi*2, 0.05)
y1 = np.sin(xpoints)
y2 = np.cos(xpoints)
trace0 = go.Scatter(
   x = xpoints,
   y = y1,
   name='Sine'
)
trace1 = go.Scatter(
   x = xpoints,
   y = y2,
   name = 'cos'
)
data = [trace0, trace1]
layout = go.Layout(title = "Sine and cos", xaxis = {'title':'angle'}, yaxis = {'title':'value'})
fig = go.Figure(data = data, layout = layout)
iplot(fig)

プロットは以下のように表示されます-

Legendsトレースオブジェクト