📜  密谋-传奇

📅  最后修改于: 2020-11-29 07:04:05             🧑  作者: Mango


默认情况下,具有多个迹线的绘图图表会自动显示图例。如果只有一条迹线,则不会自动显示。要显示,请将Layout对象的showlegend参数设置为True。

layout = go.Layoyt(showlegend = True)

图例的默认标签为跟踪对象名称。要设置图例标签,请显式设置trace的name属性。

在以下示例中,绘制了两个具有name属性的散点迹线。

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)

该图显示如下-

图例跟踪对象