Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8101965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:07:03+00:00 2026-06-05T23:07:03+00:00

in the code below, bdate and edate are both datetime.datetime() objects: pylab.barh(ypos, edate –

  • 0

in the code below, bdate and edate are both datetime.datetime() objects:

pylab.barh(ypos, edate - bdate, left=bdate, height=TRMWidth )

but this throws an AttributeError way down in dates.py._to_ordinalf() :

File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py”, line 1926, in barh
ret = ax.barh(bottom, width, height, left, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py”, line 4774, in barh
orientation=’horizontal’, **kwargs)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py”, line 4624, in bar
width = self.convert_xunits( width )
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py”, line 147, in convert_xunits
return ax.xaxis.convert_units(x)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py”, line 1312, in convert_units
ret = self.converter.convert(x, self.units, self)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 1125, in convert
return date2num(value)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 260, in date2num
else: return np.asarray([_to_ordinalf(val) for val in d])
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”, line 189, in _to_ordinalf
base = float(dt.toordinal())

AttributeError: ‘datetime.timedelta’ object has no attribute ‘toordinal’

i thought it’d be great if i could just shove datetimes at xaxis and have it
work out the details; not so much. any suggestions as to how to make dates agreaable to xaxis?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:07:04+00:00Added an answer on June 5, 2026 at 11:07 pm

    What’s happening is that matplotlib doesn’t actually use datetime objects for plotting.

    Dates are first converted into an internal floating point format. The conversion isn’t set up to handle timedeltas (which is arguably an oversight).

    You can basically do exactly what you wanted, you just need to explictly convert the dates to matplotlib’s internal format first, and then call ax.xaxis_date().

    As a quick example (Most of this is generating data to plot…):

    import datetime as dt
    import matplotlib.pyplot as plt
    import matplotlib.dates as mdates
    
    def drange(start, end, interval=dt.timedelta(days=1)):
        output = []
        while start <= end:
            output.append(start)
            start += interval
        return output
    
    # Generate a series of dates for plotting...
    edate = drange(dt.datetime(2012, 2, 1), dt.datetime(2012, 6, 15), 
                          dt.timedelta(days=5))
    bdate = drange(dt.datetime(2012, 1, 1), dt.datetime(2012, 5, 15), 
                          dt.timedelta(days=5))
    
    # Now convert them to matplotlib's internal format...
    edate, bdate = [mdates.date2num(item) for item in (edate, bdate)]
    
    ypos = range(len(edate))
    fig, ax = plt.subplots()
    
    # Plot the data
    ax.barh(ypos, edate - bdate, left=bdate, height=0.8, align='center')
    ax.axis('tight')
    
    # We need to tell matplotlib that these are dates...
    ax.xaxis_date()
    
    plt.show()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the code below are all height=100%, it works fine in chrome but it displayes
The code below sets a select menu with UI selectmenu by $('.anyclass').selectmenu(); but the
The code below will validate required fields within currently visible fieldsets, but only if
The code below works, but I suspect there is be a cleaner. Any alternative
The code below moves a div to the correct height upon mouseenter of another
The code below should print ten results but instead it prints ten test-ite. Why
The code below works fine but, in the textbox the decimal value has this
code below working fine but not in IE6, IE7, below is the code is
The code below works. But if I comment out the line Dim objRequest As
The code below happily populates an email with the week's appoinments but it lists

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.