Zuletzt aktiv 1 month ago

Paras aulas de física experimental.

Änderung 1334dc7c115b7289da2889ca9504d66171566349

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