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 8906449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:39:31+00:00 2026-06-15T02:39:31+00:00

When doing some analysis, I stumbled upon a ValueError and I could boil it

  • 0

When doing some analysis, I stumbled upon a ValueError and I could boil it down to the following simple example which can reproduce the error I got:

import numpy as np
import matplotlib.pyplot as plt
import datetime as dt

x = np.array([dt.datetime(2012, 10, 19, 10, 0, 0),
              dt.datetime(2012, 10, 19, 10, 0, 1),
              dt.datetime(2012, 10, 19, 10, 0, 2),
              dt.datetime(2012, 10, 19, 10, 0, 3)])

y = np.array([1, 3, 4, 2])

When trying to plot this simple x and y array, I have no problems with:

fig, ax = plt.subplots()
ax.plot(x, y)

or

fig, (ax1, ax2) = plt.subplots(nrows=2)
ax1.plot(x, y)

but when adding sharex=True, I get an error:

fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True)
ax1.plot(x, y)

The error message:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2445, in home
    self._update_view()
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2818, in _update_view
    self.draw()
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2796, in draw
    loc.refresh()
  File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 758, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 530, in viewlim_to_dt
    return num2date(vmin, self.tz), num2date(vmax, self.tz)
  File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 289, in num2date
    if not cbook.iterable(x): return _from_ordinalf(x, tz)
  File "C:\Python27\lib\site-packages\matplotlib\dates.py", line 203, in _from_ordinalf
    dt = datetime.datetime.fromordinal(ix)
ValueError: ordinal must be >= 1

I found an issue from matplotlib (https://github.com/matplotlib/matplotlib/issues/162) about the use of twinx with dates giving the same error. Is it the same bug? And it seems a long known bug, but not yet solved.

  • 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-15T02:39:33+00:00Added an answer on June 15, 2026 at 2:39 am

    The error is avoided if you plot something on the second axis:

    import matplotlib.pyplot as plt
    import numpy as np
    import datetime as dt
    
    x = np.array([dt.datetime(2012, 10, 19, 10, 0, 0),
                  dt.datetime(2012, 10, 19, 10, 0, 1),
                  dt.datetime(2012, 10, 19, 10, 0, 2),
                  dt.datetime(2012, 10, 19, 10, 0, 3)])
    
    y = np.array([1, 3, 4, 2])
    
    fig, (ax1, ax2) = plt.subplots(nrows = 2, sharex = True)
    ax1.plot(x, y, 'b-')
    ax2.plot(x, 1.0/y, 'r-')
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some exploratory analysis on a dataset with 27 variables, of which maybe
I've got a program which is doing some geometrical analysis in a background thread.
I am doing some data analysis in MYSQL and hoping that the following is
So I am doing some data analysis in which I am required to extract
This is a very basic example. But I am doing some data analysis and
I'm doing some analysis something like this: library(plyr) input.files <- c(file1.txt, file2.txt, file3.txt) input.data
I'm doing some specific signal analysis, and I am in need of a method
I'm doing some personal research into text analysis, and have come up with close
We're doing some code cleanup, fixing signed/unsigned comparisons, running static analysis, etc, on the
While doing some JavaScript performance tests I came up with the following piece of

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.