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

  • Home
  • SEARCH
  • 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 9127925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:23:51+00:00 2026-06-17T07:23:51+00:00

I’m using psycopg2 to pull data from a DB to get a date, and

  • 0

I’m using psycopg2 to pull data from a DB to get a date, and time where a failure was logged. I would like to graph it where the time is on the y axis, and the date is on the x axis. A dot graph seems to be ideal for this.

This is part of the code where I get the data, and use zip on it to make the two objects I want to graph,

    cur.execute("SELECT date, time FROM querytimes where server = (%s) AND date > CURRENT_DATE - (%s) AND fail = 'Yes'", (server,days,))

    # retrieve the whole result set
    data = cur.fetchall()
    # close connection
    cur.close()
    conn.close()
    # Test
    date, time = zip(*data)

These are the resulting "date" and time" objects,

(datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 10), datetime.date(2013, 1, 11), datetime.date(2013, 1, 12), datetime.date(2013, 1, 12), datetime.date(2013, 1, 13))

(datetime.time(15, 25, 3), datetime.time(15, 26, 3), datetime.time(15, 27, 4), datetime.time(15, 28, 3), datetime.time(15, 29, 3), datetime.time(15, 30, 4), datetime.time(15, 31, 3), datetime.time(15, 32, 4), datetime.time(15, 33, 3), datetime.time(15, 34, 3), datetime.time(15, 35, 3), datetime.time(15, 36, 3), datetime.time(15, 37, 3), datetime.time(15, 38, 3), datetime.time(15, 39, 3), datetime.time(15, 40, 3), datetime.time(0, 20, 4), datetime.time(6, 19, 3), datetime.time(10, 50, 3), datetime.time(2, 19, 3))

I am having problems graphing this. From what I understand these need converted to floats first before matplotlib to understand the data?

Tried using date2num and that works on the "date" object, but not sure how to do that for the "time" object.

Thanks

  • 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-17T07:23:52+00:00Added an answer on June 17, 2026 at 7:23 am

    You could achieve this easily using Pandas.

    import pandas as pd
    ts = pd.Series(times, index=dates)
    ts.plot(rot=30, style='x-')
    

    to get something like

    times by dates

    Alternative approach: datetimes as indices

    Having datetime objects as your index, not just the date objects sometimes allows for more flexibility, so personally I would represent this kind of data that way. You could do it by first combining your date and time objects

    datetimes = []
    for date, time in zip(dates, times):
        datetimes.append(datetime.datetime.combine(date, time))
    

    building your TimeSeries

    ts = pd.Series(1, index=datetimes)
    

    (1 is to indicate one failure at that moment)

    Now you could create another useful view on this kind of data which enables you to see the quantity per day.

    ts.groupby(lambda x : x.date()).sum().plot(rot=30, style='x-', kind='bar')
    

    quantity per day

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

Sidebar

Related Questions

I am using jsonparser to parse data and images obtained from json response. When
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to count the length of a string with PHP. The string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.