-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbar_line.py
More file actions
97 lines (79 loc) · 2.43 KB
/
bar_line.py
File metadata and controls
97 lines (79 loc) · 2.43 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Homework assignment
1.Create a grid graph called Vaccine Data, and display
in the graph of the data increasing then decreasing at the end.
2.Create a 4-D array and change it to a 1-D array.
3.Create 4 different Graphs in 1 figure.
4.Find out the standard Deviation for the Vaccine Data.
"""
def vaccine_data():
"""
Create a grid graph called Vaccine Data, and display
in the graph of the data increasing then decreasing at the end.
"""
import numpy as np
import matplotlib.pyplot as plt
# Create a grid graph called Vaccine Data
data = np.random.randint(0, 100, (10, 10))
# Display in the graph of the data increasing then decreasing at the end.
plt.imshow(data, cmap='hot', interpolation='nearest')
plt.title("Vaccine Data")
plt.colorbar()
plt.show()
def four_d_array():
"""
Create a 4-D array and change it to a 1-D array.
"""
import numpy as np
# Create a 4-D array
data = np.random.randint(0, 100, (10, 10, 10, 10))
# Change it to a 1-D array
data = data.flatten()
print(data)
def four_graphs():
"""
Create 4 different Graphs in 1 figure.
"""
import numpy as np
import matplotlib.pyplot as plt
# Create 4 different Graphs in 1 figure.
# graphs to be plotted: bar, line, scatter, pie
data_x = np.random.randint(0, 100, (10, 10))
data_y = np.random.randint(50, 100, (10, 10))
data_fruits = ["apples", "oranges", "mangoes", "grapes"]
data_fruits_sales = [200, 600, 400, 1000]
# heatmap graph
plt.subplot(221)
plt.imshow(data_x, cmap='hot', interpolation='nearest')
plt.title("Heatmap")
plt.colorbar()
# line graph
plt.subplot(222)
plt.plot(data_x, data_y)
plt.title('Line Graph')
plt.xlabel('X')
plt.ylabel('Y')
# scatter graph
plt.subplot(223)
plt.scatter(data_x, data_y)
plt.title('Scatter Graph')
plt.xlabel('X')
# pie graph
plt.subplot(224)
plt.pie(data_fruits_sales, labels=data_fruits, autopct='%1.1f%%')
plt.title('Pie Graph')
plt.legend()
plt.show()
def standard_deviation():
"""
Find out the standard Deviation for the Vaccine Data.
"""
import numpy as np
# Find out the standard Deviation for the Vaccine Data.
data = np.random.randint(0, 100, (10, 10))
print(f"Standard Deviation: {np.std(data)}")
if __name__ == '__main__':
vaccine_data()
four_d_array()
four_graphs()
standard_deviation()