0

I'd like to be able to visualize the difference between some lists of times on a timeline.

I can either return them with start and end time tuples:

[(0.15119, 0.43909), (0.43909, 0.72698), (0.72698, 1.01189), (1.01189, 1.2968)]

or just start time:

[0.15119, 0.43909, 0.72698, 1.01189]

And I would like to end up with something like this:

Example Graph

I've looked at graphviz, matplotlib and networkx, and am guessing this is probably a relatively simple graph. Maybe there's a different tool altogether that would make the most sense.

Could someone offer either an example or a nudge in the right direction.

MikeiLL
  • 6,282
  • 5
  • 37
  • 68
  • 2
    this might interest you: http://stackoverflow.com/questions/7684475/plotting-labeled-intervals-in-matplotlib-gnuplot – cel Jan 16 '15 at 20:26

1 Answers1

1

I think all you need to do is build a series of thick lines using your start and end values as x, and zeros as y (if I understand you correctly).

Ex:

import matplotlib.pyplot as plt
x=[(0.15119, 0.43909), (0.43909, 0.72698), (0.72698, 1.01189), (1.01189, 1.2968)]
for i in x:
    plt.plot(i,[0,0],linewidth=10)
plt.show()

BTW, you can easily make the second set of times you gave from the first (plus the last ending time) using numpy:

import numpy as np
times = np.array([0.15119, 0.43909, 0.72698, 1.01189, 1.2968])
time_pairs = np.transpose([times[:-1],times[1:]])

time_pairs.tolist()

gives: [[0.15119, 0.43909], [0.43909, 0.72698], [0.72698, 1.01189], [1.01189, 1.2968]]

David
  • 328
  • 4
  • 10
  • awesome. and thanks for the np.transpose tip, too. I'm still a bit intimidated by numpy, but will have to look up the transpose method (or class) and see what's happening there. – MikeiLL Jan 17 '15 at 04:16
  • 1
    Don't be intimidated, just play with it; there is SO MUCH good stuff in numpy! Once you understand shape and datatype, just play with one function at a time and you will be amazed at what can be done with just a handful of them. – David Feb 07 '15 at 16:28