Issue
I have two lists -
years = ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020']
profits = ['362', '622', '-409', '-92', '-148', '-130', '-128', '98', '-74', '35', '-419']
How can I plot this list, and in which chart should I use here?
I tried this code but output is not right -
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()
Wrong output which I'm getting:
Solution
Currently you have a list of strings. You should convert it to a list of floats using
years = list(map(float, years))
profits = list(map(float, profits))
If you want a list of ints, just change float
to int
.
Answered By - enzo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.