python plotly line chart 折线图

python plotly line chart 折线图

# 1 折线图数据
# trace1 - 基本格式
# trace2 - 更多参数
trace1 = go.Scatter(
    x = x1,
    y = y2,
)
trace2 = go.Scatter(
    x = x2,
    y = y2,
    mode = 'lines', # 模式:lines 线,markers 点。可用“+”相连
    name = 'line2', # 折线名,显示于图例
    connectgaps = True # 连接缺失点两端 默认False
    line = dict(
        color = ('rgb(205, 12, 24)'), # 颜色
        width = 4, #线宽
        dash = 'dash') # 虚线: dash 一一,dot ···,dashdot 一·一
) 
)

# 2 打包数据
data = [trace1,trace2]

# 3 格式
layout = dict(title = '折线',
              xaxis = dict(title = '时间'), # 横轴坐标
              yaxis = dict(title = '数量'), # 总轴坐标
              legend=dict(x=1.1,y=1) # 图例位置 
              )

# 4 打包数据+格式
fig = dict(data=data, layout=layout)

# 5 画图
py.iplot(fig, filename='styled-line')

你可能感兴趣的:(python,plotly)