okay... i've googled for about an hour and still don't seem my answer...
I am using "arrows" to plot a time line that has
|-------------|
This kind of style. But since the time line is long i would also like
to include labels in my data that would show the start -duration - end
of my data in better precision that i can eyeball it looking at the
xlabel...
so that i might get something that looks like :
1.121 (2.1) 3.221
|-----------------------------|
# ------------------------------[ snip ]
---------------------------------
#! /usr/bin/env python
"""arrows.py -- a plot of the durations
Usage: $ python arrows.py data.txt
"""
import sys
import Gnuplot
def main():
# First let's get our data form an external file and stuff it in a
list
[filename] = sys.argv[1:]
all = []
for l in open(filename).readlines():
l = l.strip().split()
all.append( [ float(l[0]), float(l[1]), float(l[2]), int(l[3]) ] )
# Split the data into four datasets by stream
# Each data set will be drawn in 'vector' style with a different
color
allData = [] # This will contain the four datasets
for stream in [1, 2, 3, 4]:
# Select the raw data for the stream
rawData = [ item for item in all if item[3] == stream ]
# Make a Gnuplot.Data to contain the raw data
data = Gnuplot.Data(rawData,
using=(1, 3, 2, '(0)'), # This gives 1-based index into the
# data for x, y, xdelta, ydelta
# ydelta is a literal 0
with='vectors arrowstyle %s' % stream) # This sets the
style of the dataset styles are defined below
#title='Voice %s' % stream) # This names the dataset for
the legend
allData.append(data)
# Set up general plot parameters
g = Gnuplot.Gnuplot(debug=1)
g.title('Overview') # (optional)
g.xlabel('Time')
g.ylabel('Event')
g('set grid')
#g('set xtics (10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120,
130, 140)')
g('set ytics (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)')
# These lines create four vector styles that have bars at each end
# The only difference between the styles is the line type they use,
# which determines the color
# Shamelessly cribbed from the gnuplot arrowstyle demo
g('set style line 1 lt 1 lw 2') # Set a line style for the vectors
g('set style line 2 lt 2 lw 2')
g('set style line 3 lt 3 lw 2')
g('set style line 4 lt 4 lw 2')
# Set an arrow style for the vectors
g('set style arrow 1 heads size screen 0.008,90 ls 1')
g('set style arrow 2 heads size screen 0.008,90 ls 2')
g('set style arrow 3 heads size screen 0.008,90 ls 3')
g('set style arrow 4 heads size screen 0.008,90 ls 4')
#g('set key outside box') # Include a legend; put it outside the
graph
# This actually does the plot
# The * makes it treat the elements of allData as individual
function arguments
# It is the same as g.plot(allData[0], allData[1], allData[2],
allData[3]
g.plot(*allData)
if __name__ == '__main__':
main()
# data here:
1.0 52.98151020408163 1 1
53.98151020408163 360.0 2 2
153.98151020408164 100.0 3 3
254.61807619047627 60.0 4 4
316.94841360544211 60.0 5 1
378.66877120181414 30.0 6 2
409.28659297052155 30.0 7 3
440.74881179138322 24.0 8 4
465.75744104308387 60.0 9 1
496.08856235827682 60.0 10 2
557.0976548752833 60.0 11 3
|