-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_09_graphics.py
executable file
·36 lines (23 loc) · 1.35 KB
/
example_09_graphics.py
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
#!/usr/bin/python3
import matplotlib.pyplot as plt
#=======================================================================================================================
def main():
in_file = "data_file.csv"
fp_in = open(in_file, "r")
ndata_list = []
for in_data in fp_in:
in_data = in_data.strip() # remove leading and trailing whitespace
data_list = in_data.split(",") # make a list (indata) from the comma-separated data items
ndata = float(data_list[2]) # ndata is the third item in the list, in the form of a floating point number
ndata = ndata * 1000 # make the numbers a bit bigger (so it is easier to read labels on graph)
ndata_list.append(ndata)
fp_in.close()
# set up a histogram using data_list and various options
n, bins, patches = plt.hist(ndata_list, 50, normed = False, cumulative = False, histtype = 'bar', log = True, facecolor = 'green', alpha = 0.75)
plt.xlabel('Runoff') # label the x axis
plt.ylabel('Frequency') # label the y axis
plt.grid(True) # put a grid on it
plt.show() # plot the graph
print("Data nicely graphed, end of run")
#=======================================================================================================================
main()