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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:29:28+00:00 2026-06-15T20:29:28+00:00

I read-in a file and plot it with pandas DataFrame . The index is

  • 0

I read-in a file and plot it with pandas DataFrame. The index is DatetimeIndex, and then I use ginput(1) method to get one point, however the coordinate which I get is wrong.

The code is as follows:

import pandas as pd
from matplotlib.dates import num2date, date2num
ts = pd.date_range('2012-04-12,16:13:09', '2012-04-14,00:13:09', freq='H')
df = pd.DataFrame(index=ts)
df[0] = 20.6

I then plot and click on the graph using ginput:

df.plot()
t = pylab.ginput(n=1) #click somewhere near 13-APR-2012

However, the first item appears to be a float

In [8]: x = t[0][0] # ~ 370631.67741935479

In [9]: num2date(x)
Out[9]: datetime.datetime(1015, 10, 3, 16, 15, 29, 32253, tzinfo=<matplotlib.dates._UTC object at 0x104196550>)
# this is way out!

The docs suggest that it should be using these floats (from datetonum):

In [10]: dt = pd.to_datetime('13-4-2012', dayfirst=True)

In [11]: date2num(dt)
Out[11]: 734606.0

What is this float, and how can I convert it to a datetime?

Note: If I remove one of the rows from the dataframe this works correctly:

df1 = df.drop(ts[1], axis=0)
...
  • 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-15T20:29:29+00:00Added an answer on June 15, 2026 at 8:29 pm

    For data indexed with a regular frequency, pandas converts the underlying index to a PeriodIndex so that the resolution of the x-tick labels are updated automatically when zooming in and out. So the ordinals you get are Period ordinals.

    In order to convert it back into datetime, you can do the following:

    In [36]: pd.Period(ordinal=int(t[0][0]), freq='H')
    Out[36]: Period('2012-04-12 18:00', 'H')
    
    In [37]: pd.Period(ordinal=int(t[0][0]), freq='H').to_timestamp()
    Out[37]: <Timestamp: 2012-04-12 18:00:00>
    

    *Timestamp is a subclass of datetime that keeps nanoseconds

    That being said, ideally we would hide the conversion from the user (or not have to do the conversion at all if possible!), as soon as I have enough time to refactor all the plotting code…

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

Sidebar

Related Questions

I am trying to read Data from a text file and then plot it
I need to read some data from an input file and plot a graph
I read file, but in the end of file i get unknown symbols: int
I am trying to read file headers using java, I want to get file
I am trying to read file and split its line to get some context(Computer
I'm having problems reading this one JPEG file using ImageIO.read(File file) - it throws
I currently use the following code to input a csv file, plot the data
I can use Plot function. Could use plot to get the pca results. But
I'd like to plot graphs with java. It should read the data from file,
if I read file by calling read() like this: unsigned char buf[512]; memset(buf, 0,

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.