-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhisto.py
More file actions
49 lines (37 loc) · 1.02 KB
/
histo.py
File metadata and controls
49 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import numpy as np
import matplotlib.pyplot as plt
s=np.random.uniform(6, 7, 25)
smin=s.min()
smax=s.max()
bin_width=(s.max()-s.min())/4
first_left=smin
second_left=smin+bin_width
third_left=smin+bin_width*2
fourth_left=smin+bin_width*3
bins_left=np.array([first_left, second_left, third_left,
fourth_left])
first_height=np.size(np.where( (s < second_left)
& ( s>=first_left) ))
second_height=np.size(np.where( (s < third_left)
& ( s>=second_left) ))
third_height=np.size(np.where( (s < fourth_left)
& ( s>=third_left) ))
fourth_height=np.size(np.where( (s < fifth_left)
& ( s>=fourth_left) ))
bins_height=np.array([first_height, second_height,
third_height, fourth_height])
plt.figure(1)
plt.subplot(2,1,1)
plt.bar(bins_left, bins_height, width = bin_width)
plt.grid()
plt.subplot(2,1,2)
plt.bar(bins_left, bins_height, width = bin_width-0.05)
plt.grid()
plt.figure(2)
plt.subplot(2,1,1)
plt.bar(bins_left, bins_height, width = bin_width)
plt.grid()
plt.subplot(2,1,2)
plt.hist(s, bins=4, color=‘m', alpha=0.75)
plt.grid()
plt.show()