31.7.17

A matplotlib script for plotting processing times.


Input 

/Users/jvyas/work/blah/my-input-1,3
/Users/jvyas/work/blah/my-input-2,4
...


Script


#!/usr/bin/env python
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import math

#########################################################

#def roundup(x):
#    return int(math.ceil(x / 10.0)) * 10

maxM = 0
fig = plt.figure()
ax1= fig.add_subplot(111)
legends = []

def plotIt(regex="tar"):
    global maxM
    global legends
    f = open('/Users/jvyas/work/rest-backend/data2.csv', 'r')
    bins = {}
    for line in f:
        # print line
        if regex in line and len(line.split(",")) == 2:
            fName, mSec = line.split(",")
            if mSec > maxM:
                maxM = mSec
                print "new max : ", line
    #           bn = roundup(int(mSec))
            bn = int(mSec)
            if bn in bins:
                bins[bn].append(fName)
            else:
                bins[bn] = [fName]
    x = []
    y = []
    i = 1
    for k in bins:
        x.append(k)
        y.append(len(bins[k]))
        i = i + 1

    print "x"
    print x
    print "y"
    print y
    print "plotting ",regex, " ", len(bins)
    lg = ax1.scatter(x, y, label=regex)
    plt.xlabel("milliseconds")
    plt.ylabel("total count")
    legends.append(lg)
    print "appended ",lg, legends

plotIt("tar,")
plotIt("war,")
plotIt("ear,")
plotIt("jar,")
plotIt("rpm,")
plotIt("gz,")
plotIt("zip,")
plotIt("tar.gz,")

print legends
plt.legend(handles=legends, loc=9)

plt.show()

Output


No comments:

Post a Comment