FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make error when trying to plot numerical data on datetime axis clearer · Issue #9211 · matplotlib/matplotlib · GitHub

Repository navigation

Make error when trying to plot numerical data on datetime axis clearer #9211

Closed

Description

Bug report

Bug summary
Plotting datetime values first, and then trying to plot numerical data raises the confusing error message below, and then a blank window appears.

Code for reproduction

import matplotlib.pyplot as plt
from datetime import datetime

fig, ax = plt.subplots()
ax.plot(datetime(2017, 1, 1), 1)
ax.plot(1, 1)
plt.show()

Actual outcome

Traceback (most recent call last):
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 136, in _draw
    self.figure.draw(renderer)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1144, in draw
    renderer, self, dsu, self.suppressComposite)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2426, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1136, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 969, in _update_ticks
    tick_tups = [t for t in self.iter_ticks()]
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 969, in <listcomp>
    tick_tups = [t for t in self.iter_ticks()]
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 912, in iter_ticks
    majorLocs = self.major.locator()
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/dates.py", line 986, in __call__
    self.refresh()
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/dates.py", line 1006, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/dates.py", line 763, in viewlim_to_dt
    return num2date(vmin, self.tz), num2date(vmax, self.tz)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/dates.py", line 401, in num2date
    return _from_ordinalf(x, tz)
  File "/Users/dstansby/miniconda3/lib/python3.6/site-packages/matplotlib/dates.py", line 254, in _from_ordinalf
    dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
ValueError: ordinal must be >= 1

Expected outcome

A sensible error message is raised, telling the user that numerical data can't be plotted on a datetime axis

Matplotlib version

  • Operating System: OSX
  • Matplotlib Version: master branch
  • Python Version: 3.6.2

Activity

  1. thomas2004ch commented on Sep 21, 2017

    @dstansby
    Why this issue is closed? The problem is not solved yet.

  2. dstansby commented on Sep 21, 2017

    MemberAuthor

    This issue isn't closed; I opened it to more clearly describe the issue.

  3. thomas2004ch commented on Sep 21, 2017

    @dstansby
    Sorry, I mis saw it. Many thanks!

  4. added this to the milestone on Sep 24, 2017
  5. modified the milestones: , on Oct 9, 2017
  6. dstansby commented on Nov 16, 2017

    MemberAuthor

    Might be fixed by #9776

  7. jklymak commented on Nov 16, 2017

    Member

    It definitely would be. But there is some skepticism that #9776 is reasonable. Certainly in the tests, there are numerous instances where folks want to bypass the units conversion and plot bare floats.

  8. onaclov2000 commented on Dec 24, 2017

    I was running 1.5.1 and seeing this issue, #6023 I upgraded to 2.1.1 still the same issue. I can put my output from command line here if you'd like, but I'm guessing it isn't fixed?

  9. tacaswell commented on Dec 24, 2017

    Member

    I think that raising here is notionally the correct behavior. If you plot with datetimes on the x-axis, then we assign units to that axis and assume that all future user data will have the same units (ex datetimes). Internally we need to get to floats eventually, but that should probably not be user exposed.

    @onaclov2000 What is the use case where you are running into this?

  10. jklymak commented on Dec 24, 2017

    Member

    I think its correct to Raise here, but it ideally should Raise in Matplotlib with a nicer message. I think this is doable w/o making a mess. OTOH, if we decide to do #9776 (lockout different units) then this won't happen anymore. This is all part of the Categorical discussion

  11. jklymak commented on Mar 24, 2018

    Member

    Think this is closed #10084. Feel free to re-open if not...

  12. modified the milestones: , v2.2.0 on Mar 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL