import plotly.graph_objects as go
import plotly.io as pio

# 创建示例数据
x = [1, 2, 3, 4, 5]
y1 = [10, 15, 13, 17, 16]
y2 = [16, 5, 11, 9, 10]
y3 = [6, 8, 9, 5, 4]
y4 = [10, 15, 13, 17, 16]
y5 = [16, 5, 11, 9, 10]
y6 = [6, 8, 9, 5, 4]
y7 = [10, 15, 13, 17, 16]
y8 = [16, 5, 11, 9, 10]
y9 = [6, 8, 9, 5, 4]
y10 = [10, 15, 13, 17, 16]
y11 = [16, 5, 11, 9, 10]
y12 = [6, 8, 9, 5, 4]
y13 = [10, 15, 13, 17, 16]
y14 = [16, 5, 11, 9, 10]
y15 = [6, 8, 9, 5, 4]

# 创建图表
fig = go.Figure()

# 添加多个系列
fig.add_trace(go.Scatter(x=x, y=y1, mode='lines+markers', name='Series 1'))
fig.add_trace(go.Scatter(x=x, y=y2, mode='lines+markers', name='Series 2'))
fig.add_trace(go.Scatter(x=x, y=y3, mode='lines+markers', name='Series 3'))
fig.add_trace(go.Scatter(x=x, y=y4, mode='lines+markers', name='Series 4'))
fig.add_trace(go.Scatter(x=x, y=y5, mode='lines+markers', name='Series 5'))
fig.add_trace(go.Scatter(x=x, y=y6, mode='lines+markers', name='Series 6'))
fig.add_trace(go.Scatter(x=x, y=y7, mode='lines+markers', name='Series 7'))
fig.add_trace(go.Scatter(x=x, y=y8, mode='lines+markers', name='Series 8'))
fig.add_trace(go.Scatter(x=x, y=y9, mode='lines+markers', name='Series 9'))
fig.add_trace(go.Scatter(x=x, y=y10, mode='lines+markers', name='Series 10'))
fig.add_trace(go.Scatter(x=x, y=y11, mode='lines+markers', name='Series 11'))
fig.add_trace(go.Scatter(x=x, y=y12, mode='lines+markers', name='Series 12'))
fig.add_trace(go.Scatter(x=x, y=y13, mode='lines+markers', name='Series 13'))
fig.add_trace(go.Scatter(x=x, y=y14, mode='lines+markers', name='Series 14'))
fig.add_trace(go.Scatter(x=x, y=y15, mode='lines+markers', name='Series 15'))

# 更新布局以解决图例展示不全问题
fig.update_layout(
    legend=dict(
        orientation="h",
        yanchor="bottom",
        y=1.02,
        xanchor="right",
        x=1
    ),
    margin=dict(b=40, t=40)
)

# 使用 write_image 方法输出图形
pio.write_image(fig, 'line_chart.png')

fig.show()
