0

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?

0

1 Answer 1

1

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()

enter image description here

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.