Reputation: 91
i am attempting to chart some stock info on matplotlib from a csv file
i put data from each column into a list, so date is one list, price is another and so on
when i plot price as a function of time, instead of getting a regular stock chart, it gives me a huge mess of squiggly lines everywhere
ive googled some examples and the solutions are above and beyond what i need and i cannot differentiate which part is just simply plotting date on the x axis
date = ['Jan 24, 2018', 'Jan 23, 2018', 'Jan 23, 2018']
price = [28.14, 29.01, 28.75]
plt.plot(date, price)
plt.show()
the code above is essentially how ive got it
can someone perhaps show me a simple example or link me a good matplotlib tutorial?
Upvotes: 0
Views: 1520
Reputation: 2558
I noticed that Jan 23, 2018
twice in your date
list. Did you mean to plot separate dates? Here is a modified example that seems to work just fine:
date = ['Jan 24, 2018', 'Jan 25, 2018', 'Jan 26, 2018']
price = [28.14, 29.01, 28.75]
plt.plot(date, price)
plt.show()
matplotlib
will order the string values in date
alphabetically. This is what is causing the values to appear scrambled. It would be a good idea to convert the strings to datetime
objects before plotting them.
Upvotes: 1