我有两份名单-
years = ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020']
profits = ['362', '622', '-409', '-92', '-148', '-130', '-128', '98', '-74', '35', '-419']
如何绘制此列表,以及应在此处使用哪个图表
我尝试了此代码,但输出不正确-
from matplotlib import pyplot as plt
# Figure Size
fig = plt.figure(figsize =(10, 7))
# Horizontal Bar Plot
plt.bar(years, profits)
# Show Plot
plt.show()
我得到的输出错误:
当前您有一个字符串列表。您应该使用
如果您想要一个int列表,只需将
float
更改为int
相关问题 更多 >
编程相关推荐