折线图使用绘图

问题描述 投票:0回答:1

以下是我的数据框。

enter image description here

如何使用绘图创建一条线,其中x轴包含年份,而y轴包含该特定年份的产值

python python-3.x pandas plotly linechart
1个回答
0
投票

IIUC,此代码应完成此工作:

import plotly.graph_objects as go
import pandas as pd

df = pd.DataFrame({'Minerals':['Nat. Gas'],
              '2013':[5886],
              '2014':[5258],
              '2015':[5214],
              '2016':[5073],
              '2017':[5009],})

fig = go.Figure(data=go.Scatter(x=df.columns[1:],
                                y=df.loc[0][1:]))
fig.show()

您得到:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.