FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LearnPython/python_visual_animation.py at master · psvm-enter/LearnPython · GitHub
psvm-enter
/
LearnPython
Public
forked from
xianhu/LearnPython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
LearnPython
/
python_visual_animation.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
161 lines (122 loc) · 3.6 KB
Breadcrumbs
LearnPython
/
python_visual_animation.py
Copy path
File metadata and controls
161 lines (122 loc) · 3.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# _*_ coding: utf-8 _*_
"""
python_visual_animation.py by xianhu
"""
import
numpy
as
np
import
matplotlib
import
matplotlib
.
pyplot
as
plt
import
matplotlib
.
font_manager
as
fm
from
mpl_toolkits
.
mplot3d
import
Axes3D
# 解决中文乱码问题
myfont
=
fm
.
FontProperties
(
fname
=
"/Library/Fonts/Songti.ttc"
,
size
=
14
)
matplotlib
.
rcParams
[
"axes.unicode_minus"
]
=
False
def
simple_plot
():
"""
simple plot
"""
# 生成画布
plt
.
figure
(
figsize
=
(
8
,
6
),
dpi
=
80
)
# 打开交互模式
plt
.
ion
()
# 循环
for
index
in
range
(
100
):
# 清除原有图像
plt
.
cla
()
# 设定标题等
plt
.
title
(
"动态曲线图"
,
fontproperties
=
myfont
)
plt
.
grid
(
True
)
# 生成测试数据
x
=
np
.
linspace
(
-
np
.
pi
+
0.1
*
index
,
np
.
pi
+
0.1
*
index
,
256
,
endpoint
=
True
)
y_cos
,
y_sin
=
np
.
cos
(
x
),
np
.
sin
(
x
)
# 设置X轴
plt
.
xlabel
(
"X轴"
,
fontproperties
=
myfont
)
plt
.
xlim
(
-
4
+
0.1
*
index
,
4
+
0.1
*
index
)
plt
.
xticks
(
np
.
linspace
(
-
4
+
0.1
*
index
,
4
+
0.1
*
index
,
9
,
endpoint
=
True
))
# 设置Y轴
plt
.
ylabel
(
"Y轴"
,
fontproperties
=
myfont
)
plt
.
ylim
(
-
1.0
,
1.0
)
plt
.
yticks
(
np
.
linspace
(
-
1
,
1
,
9
,
endpoint
=
True
))
# 画两条曲线
plt
.
plot
(
x
,
y_cos
,
"b--"
,
linewidth
=
2.0
,
label
=
"cos示例"
)
plt
.
plot
(
x
,
y_sin
,
"g-"
,
linewidth
=
2.0
,
label
=
"sin示例"
)
# 设置图例位置,loc可以为[upper, lower, left, right, center]
plt
.
legend
(
loc
=
"upper left"
,
prop
=
myfont
,
shadow
=
True
)
# 暂停
plt
.
pause
(
0.1
)
# 关闭交互模式
plt
.
ioff
()
# 图形显示
plt
.
show
()
return
# simple_plot()
def
scatter_plot
():
"""
scatter plot
"""
# 打开交互模式
plt
.
ion
()
# 循环
for
index
in
range
(
50
):
# 清除原有图像
# plt.cla()
# 设定标题等
plt
.
title
(
"动态散点图"
,
fontproperties
=
myfont
)
plt
.
grid
(
True
)
# 生成测试数据
point_count
=
5
x_index
=
np
.
random
.
random
(
point_count
)
y_index
=
np
.
random
.
random
(
point_count
)
# 设置相关参数
color_list
=
np
.
random
.
random
(
point_count
)
scale_list
=
np
.
random
.
random
(
point_count
)
*
100
# 画散点图
plt
.
scatter
(
x_index
,
y_index
,
s
=
scale_list
,
c
=
color_list
,
marker
=
"o"
)
# 暂停
plt
.
pause
(
0.2
)
# 关闭交互模式
plt
.
ioff
()
# 显示图形
plt
.
show
()
return
# scatter_plot()
def
three_dimension_scatter
():
"""
3d scatter plot
"""
# 生成画布
fig
=
plt
.
figure
()
# 打开交互模式
plt
.
ion
()
# 循环
for
index
in
range
(
50
):
# 清除原有图像
fig
.
clf
()
# 设定标题等
fig
.
suptitle
(
"三维动态散点图"
,
fontproperties
=
myfont
)
# 生成测试数据
point_count
=
100
x
=
np
.
random
.
random
(
point_count
)
y
=
np
.
random
.
random
(
point_count
)
z
=
np
.
random
.
random
(
point_count
)
color
=
np
.
random
.
random
(
point_count
)
scale
=
np
.
random
.
random
(
point_count
)
*
100
# 生成画布
ax
=
fig
.
add_subplot
(
111
,
projection
=
"3d"
)
# 画三维散点图
ax
.
scatter
(
x
,
y
,
z
,
s
=
scale
,
c
=
color
,
marker
=
"."
)
# 设置坐标轴图标
ax
.
set_xlabel
(
"X Label"
)
ax
.
set_ylabel
(
"Y Label"
)
ax
.
set_zlabel
(
"Z Label"
)
# 设置坐标轴范围
ax
.
set_xlim
(
0
,
1
)
ax
.
set_ylim
(
0
,
1
)
ax
.
set_zlim
(
0
,
1
)
# 暂停
plt
.
pause
(
0.2
)
# 关闭交互模式
plt
.
ioff
()
# 图形显示
plt
.
show
()
return
# three_dimension_scatter()
Back
|
FazBrowse Home
|
New Git URL