forked from ls1248659692/python_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_visualization.py
More file actions
78 lines (57 loc) · 1.63 KB
/
data_visualization.py
File metadata and controls
78 lines (57 loc) · 1.63 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
#!/usr/bin/python
# coding=utf8
from report_util.data_analysis_head import *
def start_plot():
x = np.arange(0, 10)
y = map(lambda x: x ** 2, x)
z = map(lambda x: x ** 2.5, x)
print x
print y
print z
# Labeling the Axes and Title
plt.title("Graph Drawing")
plt.xlabel("Time")
plt.ylabel("Distance")
# Simple Plot
plt.plot(x, y)
plt.plot(x, z)
plt.plot(x, y, 'r')
plt.plot(x, y, '>')
# Annotate
plt.annotate(xy=[x[1] - 0.5, y[1] - 5], s='Second Entry')
plt.annotate(xy=[x[2] - 0.5, y[2] - 5], s='Third Entry')
# Adding Legends
# plt.legend(['Race1'], loc=4)
## 以下选择一个运行,否者无法生成图片
plt.show()
# plt.savefig('test.png')
def draw_box():
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
df.plot.box()
plt.show()
def draw_heatmap():
data = [{2, 3, 4, 1}, {6, 3, 5, 2}, {6, 3, 5, 4}, {3, 7, 5, 4}, {2, 8, 1, 5}]
Index = ['I1', 'I2', 'I3', 'I4', 'I5']
Cols = ['C1', 'C2', 'C3', 'C4']
df = pd.DataFrame(data, index=Index, columns=Cols)
plt.pcolor(df)
plt.show()
def draw_scatter():
df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
df.plot.scatter(x='a', y='b')
plt.show()
def draw_bubble():
# create data
x = np.random.rand(40)
y = np.random.rand(40)
z = np.random.rand(40)
colors = np.random.rand(40)
# use the scatter function
plt.scatter(x, y, s=z * 1000, c=colors)
plt.show()
if __name__ == "__main__":
# start_plot()
# draw_box()
# draw_heatmap()
# draw_scatter()
draw_bubble()