Python Forum
How to plot date series in matplotlib?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to plot date series in matplotlib?
#1
I used the following code to format my series into timestamps, but I would like to now visualise it with pyplot. I based the format on the python datetime object, so to plot time with matplotlib I converted my column into a python datetime and then to the pyplot format...

Datetime format

spreads['Created at'] = pd.to_datetime(timedata).apply(lambda x:x.strftime('%H:%M:%S'))
outcome : 07:20:00

Next step pyplot format

> import matplotlib.pyplot as plt import random
 
 x = matplotlib.dates.date2num(spreads['Created at']) y =
 y = [i+random.gauss(0,1) for i,_ in enumerate(x)]
 
 plt.plot(x,y)
AttributeError: 'str' object has no attribute 'toordinal'

Could somebody explain me what is wrong with my code?
Reply


Messages In This Thread
How to plot date series in matplotlib? - by StrybolData - Jan-24-2018, 10:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fit straight line to pandas time series data with semilog plot schniefen 2 1,529 Mar-10-2023, 01:08 PM
Last Post: jefsummers
  Plot time series data schniefen 3 1,303 Mar-04-2023, 04:22 PM
Last Post: noisefloor
  matplotlib : Raster Plot adithyakrish 1 3,678 May-28-2019, 05:04 AM
Last Post: heiner55
  Need to convert a date and price from a list into appropriate date format & currency SilverLeaf90 1 1,954 Mar-23-2019, 09:41 PM
Last Post: Yoriz
  How to customize x axis in matplotlib.pyplot for a scatter plot? wlsa 9 8,189 Nov-10-2018, 01:32 AM
Last Post: wlsa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020