为了账号安全,请及时绑定邮箱和手机立即绑定

在 matplotlib 中,一个情节中有很多行

在 matplotlib 中,一个情节中有很多行

犯罪嫌疑人X 2022-09-06 21:21:42
我正在尝试从csv文件中在matplotlib中绘制21行。我通过做大熊猫制作了一个“粗糙”的情节。df.plot(x='Date')然而,我在使用matplotlib时并没有取得多大成功。到目前为止,我尝试过的事情:# Start by creating figure and axisfig, ax = plt.subplots(figsize=(10, 10))# Plot the dataax.plot(df['Date'], df['1 Heildartekjur'], label='Heildartekjur')ax.plot(df['Date'], df['11 Skatttekjur'], label='Skatttekjur')ax.plot(df['Date'], df['111 Skattar á tekjur og hagnað'], label='Skattar á tekjur og hagnað')ax.plot(df['Date'], df['112 Skattar á launagreiðslur og vinnuafl'], label='Skattar á launagreiðslur og vinnuafl')ax.plot(df['Date'], df['113 Eignarskattar'], label='Eignarskattar')ax.legend();这工作正常,但是一旦我再添加一行,我就会收到一个错误:# Start by creating figure and axisfig, ax = plt.subplots(figsize=(10, 10))# Plot the dataax.plot(df['Date'], df['1 Heildartekjur'], label='Heildartekjur')ax.plot(df['Date'], df['11 Skatttekjur'], label='Skatttekjur')ax.plot(df['Date'], df['111 Skattar á tekjur og hagnað'], label='Skattar á tekjur og hagnað')ax.plot(df['Date'], df['112 Skattar á launagreiðslur og vinnuafl'], label='Skattar á launagreiðslur og vinnuafl')ax.plot(df['Date'], df['113 Eignarskattar'], label='Eignarskattar')ax.plot(df['Date'], df['114 Skattar vöru og þjónustu'], label='Skattar á vöru og þjónustu')ax.legend();KeyError: '114 Skattar vöru og þjónustu'我确实从csv文件中复制/粘贴了这个,所以拼写应该不是问题。我试过df.unstack(fill_value=0).plot()image = ax.plot(df['Date'], df)给出错误:ValueError: view limit minimum -36866.545000000006 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units但“日期”是日期时间单位。我没有在 matplotlib 文档网站上找到任何可以帮助我的东西。我没有尝试任何循环,只是想在x轴上。我在互联网上找到的大多数教程都有3行,使用3次。我不确定如何共享csv文件,但我很乐意这样做。forDatedf.plot(x, x, legend='Legend')我很确定这很容易,但我还没有弄清楚这一点:D
查看完整描述

1 回答

?
湖上湖

TA贡献2003条经验 获得超2个赞

在命令中发现间距错误,应该是。工作正常。仍然认为绘制所有数据应该更容易:Dax.plot(df['Date'], df['114 Skattar  vöru og þjónustu'], label='Skattar á vöru og þjónustu]')

很抱歉无缘无故提出问题。


查看完整回答
反对 回复 2022-09-06
  • 1 回答
  • 0 关注
  • 110 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信