generate.py
· 1.1 KiB · Python
Bruto
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
width = 20 # cm
height = 15 # cm
if len(sys.argv) < 4:
print "Usage: generate.py data.txt title output"
exit(1)
output = sys.argv[3]
title = sys.argv[2].decode(encoding='UTF-8',errors='strict')
data = np.fromfile(sys.argv[1], sep='\n')
num_bins = 28
avg = np.average(data)
std = np.std(data)
fig, ax = plt.subplots()
n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled')
print "Média: %s Desvio Padrão: %s" %(avg, std)
ax.axvline(avg, color='red', label="Média = %.2f s" %avg)
ax.axvline(avg-std, color='lightblue', label="Média - Desvio Padrão = %.2f s" %(avg-std))
ax.axvline(avg+std, color='darkblue', label="Média + Desvio Padrão = %.2f s" % (avg+std))
ax.set_xlabel('Tempo (s)')
ax.set_ylabel('Contagem (n)')
ax.set_title(title)
ax.set_ylim( None, n.max() * 1.2)
legend = ax.legend(loc='upper left', shadow=True, prop={'size':10})
fig.tight_layout()
fig.set_size_inches(width / 2.54, height / 2.54)
plt.savefig('%s.png' %output, dpi=100)
| 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | from __future__ import unicode_literals |
| 4 | |
| 5 | import sys |
| 6 | import numpy as np |
| 7 | import matplotlib.mlab as mlab |
| 8 | import matplotlib.pyplot as plt |
| 9 | |
| 10 | width = 20 # cm |
| 11 | height = 15 # cm |
| 12 | |
| 13 | if len(sys.argv) < 4: |
| 14 | print "Usage: generate.py data.txt title output" |
| 15 | exit(1) |
| 16 | |
| 17 | output = sys.argv[3] |
| 18 | title = sys.argv[2].decode(encoding='UTF-8',errors='strict') |
| 19 | |
| 20 | data = np.fromfile(sys.argv[1], sep='\n') |
| 21 | |
| 22 | num_bins = 28 |
| 23 | avg = np.average(data) |
| 24 | std = np.std(data) |
| 25 | |
| 26 | fig, ax = plt.subplots() |
| 27 | n, bins, patches = ax.hist(data, num_bins, color='burlywood', histtype='stepfilled') |
| 28 | |
| 29 | print "Média: %s Desvio Padrão: %s" %(avg, std) |
| 30 | |
| 31 | ax.axvline(avg, color='red', label="Média = %.2f s" %avg) |
| 32 | ax.axvline(avg-std, color='lightblue', label="Média - Desvio Padrão = %.2f s" %(avg-std)) |
| 33 | ax.axvline(avg+std, color='darkblue', label="Média + Desvio Padrão = %.2f s" % (avg+std)) |
| 34 | |
| 35 | ax.set_xlabel('Tempo (s)') |
| 36 | ax.set_ylabel('Contagem (n)') |
| 37 | ax.set_title(title) |
| 38 | ax.set_ylim( None, n.max() * 1.2) |
| 39 | |
| 40 | legend = ax.legend(loc='upper left', shadow=True, prop={'size':10}) |
| 41 | fig.tight_layout() |
| 42 | |
| 43 | fig.set_size_inches(width / 2.54, height / 2.54) |
| 44 | plt.savefig('%s.png' %output, dpi=100) |