75 import matplotlib.pyplot
as plt
76 import matplotlib.patches
as patches
77 import matplotlib.ticker
as ticker
81 print 'Usage: ' + sys.argv[0] +
' <file.tsv>\n'
83 elif sys.argv[1] ==
'--version':
84 print 'ccl_plot_events.py v2.0.0\n'
86 elif not os.path.isfile(sys.argv[1]):
87 print "File not found: '" + sys.argv[1] +
"'\n"
92 pdat = numpy.genfromtxt(sys.argv[1], delimiter=
'\t', dtype=
None, names=(
'queue',
't_start',
't_end',
'event'))
95 queues = numpy.unique(pdat[
'queue']).tolist()
97 num_queues = len(queues)
102 ax = plt.axes([0.1, 0.1, 0.71, 0.8])
104 plt.grid(
True, axis=
'x')
106 plt.axis([min(pdat[
't_start']), max(pdat[
't_end']), -0.5, num_queues - 0.5])
108 plt.yticks(range(num_queues), queues, size=
'small')
111 uniq_evts = numpy.unique(pdat[
'event']).tolist()
113 num_uniq_evts = len(uniq_evts)
115 cmap = pylab.cm.get_cmap(
'spectral')
116 uniq_colors = [x*cmap.N/num_uniq_evts
for x
in range(num_uniq_evts)]
120 for uniq_evt
in uniq_evts:
122 uei = uniq_evts.index(uniq_evt)
124 color = cmap(uniq_colors[uei])
126 ptch = patches.Patch(edgecolor=
'black', facecolor=color, linestyle=
'solid', fill=
True)
134 y = queues.index(event[
'queue']) - 0.4
135 width = event[
't_end'] - event[
't_start']
137 uei = uniq_evts.index(event[
'event'])
140 color = cmap(uniq_colors[uei])
142 rect = patches.Rectangle((x, y), width, 0.8, edgecolor=
'none', facecolor=color, fill=
True)
143 plt.gca().add_patch(rect)
146 plt.legend(handles, uniq_evts, borderaxespad=0, bbox_to_anchor=(1.02, 1), loc=2, prop={
'size':
'x-small'})