我正在处理索引数据帧immigration
,如下所示:
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
State
California 23.545039 28.247513 31.148935 33.117711 34.541266 35.618537 36.462176 37.140750 37.698386 38.164771
New York 21.176802 21.741915 22.279820 22.792436 23.281506 23.748615 24.195210 24.622614 25.032038 25.424592
New Jersey 12.245407 13.042893 13.785051 14.477447 15.124923 15.731713 16.301534 16.837667 17.343011 17.820146
Florida 3.166562 3.043899 2.934493 2.836304 2.747693 2.667322 2.594094 2.527096 2.465566 2.408861
我想使用plotly
为每个州在x轴上绘制年份的折线图,并添加复选框,以便用户可以选择在图表中显示哪个州。
我在尝试创建折线图的第一步就陷入了困境。看来我没有正确切片数据框...?
data = [
go.Scatter(
x=immigration.iloc[0],
y=immigration.loc["State"]
)
]
layout = go.Layout(
title='Immigration',
yaxis=dict(title='Immigration %'),
xaxis=dict(title='Years')
)
fig = go.Figure(data=data, layout=layout)