-1

I'm trying to show the progression of y value over x time - y is a float type, and x is a datetime type. I know I'm most likely just missing something, but I've looked all over StackOverflow, GitHub, and the docs and I can't figure out how to plot a Datetime against a Float (I'd like the plot to show the date in a human-readable format when it shows the plot).

This is the dataframe:

          Date       High        Low       Open      Close    Volume  Adj Close
0   2019-09-19  20.139999  17.610001  18.750000  20.110001  11486300  20.110001
1   2019-09-20  21.000000  19.150000  20.180000  19.309999   2011500  19.309999
2   2019-09-23  19.950001  18.540001  19.400000  18.809999    668100  18.809999

Sorry if that isn't formatted right - here is a pastebin link to read it easier: https://pastebin.com/2Vj7am49

Everything is a float, except for Volume (int) and Date (datetime) I'm using Seaborn, and the dates span multiple years - 2019 to 2021.

Landon
  • 117
  • 9
  • this should help you https://stackoverflow.com/questions/41815126/plot-datetime-date-pandas – drops Aug 21 '20 at 18:33
  • That is using matplotlib, not seaborn. – Landon Aug 21 '20 at 18:36
  • seaborn is an API for matplotlib, so it doesn't make much sense to say, _not seaborn_. – Trenton McKinney Aug 21 '20 at 22:28
  • Please update your question with more details about what you are actually trying to do and why your attempts don't work. You've rejected several suggested solutions by providing new information that isn't in your posted question (using seaborn, data spans multiple years). These details should be in your question. – Craig Aug 21 '20 at 22:36

1 Answers1

0

How about using the "-" operator for date objects to get the number of days from some initial date?

# grab earliest date from dataset: firstYear, firstMonth, firstDay
firstDate = datetime.date(firstYear, firstMonth, firstDay)
# read/convert all of your datetime.date objects into an iterable called `dates`
numDaysSinceFirstDate = [(d - firstDate).days for d in dates]

This will now be a list of scalars that you can plot as an (x, y) time series. If you want to keep the original string representation for your data, it looks like you can set custom ticks for your x-axis in seaborn using the isoformat() property of your datetime object and the set_xticks method. Not surprisingly, there is a corresponding set_yticks method if you choose to plot the data opposite what I proposed.

joe.dinius
  • 336
  • 1
  • 10