Title: Cannot use a timedelta Rectangle width with a datetime axis · Issue #4916 · matplotlib/matplotlib · GitHub
Open Graph Title: Cannot use a timedelta Rectangle width with a datetime axis · Issue #4916 · matplotlib/matplotlib
X Title: Cannot use a timedelta Rectangle width with a datetime axis · Issue #4916 · matplotlib/matplotlib
Description: I would like to draw a rectangle to represent the weekend on a plot whose x-axis is time. In an IPython Notebook: %pylab inline dt = datetime.datetime dates = [ dt(2015, 1, 1), dt(2015, 1, 2), dt(2015, 1, 3), dt(2015, 1, 4), dt(2015, 1, ...
Open Graph Description: I would like to draw a rectangle to represent the weekend on a plot whose x-axis is time. In an IPython Notebook: %pylab inline dt = datetime.datetime dates = [ dt(2015, 1, 1), dt(2015, 1, 2), dt(2...
X Description: I would like to draw a rectangle to represent the weekend on a plot whose x-axis is time. In an IPython Notebook: %pylab inline dt = datetime.datetime dates = [ dt(2015, 1, 1), dt(2015, 1, 2), dt(2...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/4916
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot use a timedelta Rectangle width with a datetime axis","articleBody":"I would like to draw a rectangle to represent the weekend on a plot whose x-axis is time. In an IPython Notebook:\n\n```\n%pylab inline\ndt = datetime.datetime\ndates = [\n dt(2015, 1, 1),\n dt(2015, 1, 2),\n dt(2015, 1, 3),\n dt(2015, 1, 4),\n dt(2015, 1, 5),\n ]\ndata = [56.0, 53.2, 57.8, 59.1, 55.5]\ngca().add_patch(Rectangle(\n xy=(dt(2015, 1, 3), 50.0),\n width=datetime.timedelta(days=2), \n height=1.0,\n ))\nplot(dates, data)\n```\n\nThe big problem is that the above code dies with an exception.\n\n```\nAttributeError Traceback (most recent call last)\n\u003cipython-input-13-b4545adc3ff2\u003e in \u003cmodule\u003e()\n 12 xy=(dt(2015, 1, 3), 50.0),\n 13 width=datetime.timedelta(days=2),\n---\u003e 14 height=1.0,\n 15 ))\n 16 plot(dates, data)\n\n...\n\n/home/brhodes/.v/misc/lib/python2.7/site-packages/matplotlib/dates.pyc in _to_ordinalf(dt)\n 202 dt -= delta\n 203 \n--\u003e 204 base = float(dt.toordinal())\n 205 if hasattr(dt, 'hour'):\n 206 base += (dt.hour / HOURS_PER_DAY + dt.minute / MINUTES_PER_DAY +\n\nAttributeError: 'datetime.timedelta' object has no attribute 'toordinal'\n```\n\nThe other problem is that my backup plan, of replacing the `timedelta()` with the floating-point value 2.0, destroys the date-ness of the `x` axis. It reverts to being a float that does not display as a date.\n\nWhy is a `timedelta` not a valid increment or offset with which I can express width along a datetime x-axis?\n\nThanks for any help you can provide!\n","author":{"url":"https://github.com/brandon-rhodes","@type":"Person","name":"brandon-rhodes"},"datePublished":"2015-08-13T20:15:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/4916/matplotlib/issues/4916"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:850289f2-3e78-f879-4f43-b9be8a252747 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85A8:2C9FC7:946E8C:C3FA95:6A53146B |
| html-safe-nonce | dbe8f17ac7240efdb4c6fd5d553c55a4998161beff6171908bad9b9f236852cf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUE4OjJDOUZDNzo5NDZFOEM6QzNGQTk1OjZBNTMxNDZCIiwidmlzaXRvcl9pZCI6Ijc4Nzg2Mjc0MTYxNjc2MTc2NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fdde2d17bf0136d03a962df63c5430cd574d28b8dc323d45af87c058d51f3302 |
| hovercard-subject-tag | issue:100858794 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/4916/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2e02fc9a2e8875fa7213a9747f626351f6e7164c73a1394642481549a081eb21/matplotlib/matplotlib/issues/4916 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2e02fc9a2e8875fa7213a9747f626351f6e7164c73a1394642481549a081eb21/matplotlib/matplotlib/issues/4916 |
| og:image:alt | I would like to draw a rectangle to represent the weekend on a plot whose x-axis is time. In an IPython Notebook: %pylab inline dt = datetime.datetime dates = [ dt(2015, 1, 1), dt(2015, 1, 2), dt(2... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brandon-rhodes |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width