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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:29:57+00:00 2026-05-26T01:29:57+00:00

I have a data sample which looks like this: a 10:15:22 10:15:30 OK b

  • 0

I have a data sample which looks like this:

a 10:15:22 10:15:30 OK
b 10:15:23 10:15:28 OK
c 10:16:00 10:17:10 FAILED
b 10:16:30 10:16:50 OK

What I want is to plot the above data in the following way:

captions ^
  |
c |         *------*
b |   *---*    *--*
a | *--*
  |___________________
                     time >

With the color of lines depending on the OK/FAILED status of the data point. Labels (a/b/c/...) may or may not repeat.

As I’ve gathered from documentation for gnuplot and matplotlib, this type of a plot should be easier to do in the latter as it’s not a standard plot and would require some preprocessing.

The question is:

  1. Is there a standard way to do plots like this in any of the tools?
  2. If not, how should I go about plotting this data (pointers to relevant tools/documentation/functions/examples which do something-kinda-like the thing described here)?
  • 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-05-26T01:29:58+00:00Added an answer on May 26, 2026 at 1:29 am

    Updated: Now includes handling the data sample and uses mpl dates functionality.

    import matplotlib.pyplot as plt
    from matplotlib.dates import DateFormatter, MinuteLocator, SecondLocator
    import numpy as np
    from StringIO import StringIO
    import datetime as dt
    
    ### The example data
    a=StringIO("""a 10:15:22 10:15:30 OK
    b 10:15:23 10:15:28 OK
    c 10:16:00 10:17:10 FAILED
    b 10:16:30 10:16:50 OK
    """)
    
    #Converts str into a datetime object.
    conv = lambda s: dt.datetime.strptime(s, '%H:%M:%S')
    
    #Use numpy to read the data in. 
    data = np.genfromtxt(a, converters={1: conv, 2: conv},
                         names=['caption', 'start', 'stop', 'state'], dtype=None)
    cap, start, stop = data['caption'], data['start'], data['stop']
    
    #Check the status, because we paint all lines with the same color 
    #together
    is_ok = (data['state'] == 'OK')
    not_ok = np.logical_not(is_ok)
    
    #Get unique captions and there indices and the inverse mapping
    captions, unique_idx, caption_inv = np.unique(cap, 1, 1)
    
    #Build y values from the number of unique captions.
    y = (caption_inv + 1) / float(len(captions) + 1)
    
    #Plot function
    def timelines(y, xstart, xstop, color='b'):
        """Plot timelines at y from xstart to xstop with given color."""   
        plt.hlines(y, xstart, xstop, color, lw=4)
        plt.vlines(xstart, y+0.03, y-0.03, color, lw=2)
        plt.vlines(xstop, y+0.03, y-0.03, color, lw=2)
    
    #Plot ok tl black    
    timelines(y[is_ok], start[is_ok], stop[is_ok], 'k')
    #Plot fail tl red
    timelines(y[not_ok], start[not_ok], stop[not_ok], 'r')
    
    #Setup the plot
    ax = plt.gca()
    ax.xaxis_date()
    myFmt = DateFormatter('%H:%M:%S')
    ax.xaxis.set_major_formatter(myFmt)
    ax.xaxis.set_major_locator(SecondLocator(interval=20)) # used to be SecondLocator(0, interval=20)
    
    #To adjust the xlimits a timedelta is needed.
    delta = (stop.max() - start.min())/10
    
    plt.yticks(y[unique_idx], captions)
    plt.ylim(0,1)
    plt.xlim(start.min()-delta, stop.max()+delta)
    plt.xlabel('Time')
    plt.show()
    

    Resulting image

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

Sidebar

Related Questions

I have a StaffLookup table which looks like this. UserSrn | UserName | ManagerSrn
I have some data which I am formatting like this: // ... imagine populating
I have a python script which outputs lots of data, sample is as below.
I have the following sample data: Id Name Quantity 1 Red 1 2 Red
I have a table that looks something like this: CREATE TABLE student_results(id integer, name
I have a table of results that looks like this: score_id, uid, af_id, level,
I have a data frame the first columns of which are a sample ID
I have some data like this: 1 2 3 4 5 9 2 6
I have simple SSIS package which reads data from flat file and insert into
I have a very simple WPF application in which I am using data binding

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.