2D折线图绘制
主要模块pyplot1
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
32import matplotlib.pyplot as plt
# 读取数据
file = open("./dataset.txt")
dataSet = []
try:
while True:
line = file.readline()
dataSet.append(line)
if not line:
break
pass
finally:
file.close()
# x,y 必须是相同的维度
# y = np.arange(0, 12000, 500) # 步长500
x, y = dataSet # 这里用你自己的
# x = y = np.arange(0, 1, 0.1) # 示例数据
plt.figure()
# color [r:red g:green b:blue m c] mark [s = square '^' '*' 'o' 'x']
plt.plot(y,x,'rs',label = str)
plt.plot(y,x,'r')
plt.xlabel("Number of features extracted")
plt.ylabel("Accuracy(F1)")
plt.grid() # 添加网格
plt.ylim(0, 1) # y轴 范围限制
plt.legend()
plt.show()
3D图绘制
主要模块 axes3d1
2
3
4
5
6
7
8
9
10
11
12
13
14
15import mpl_toolkits.mplot3d.axes3d as p3
fig_num = 1
fig = plt.figure(fig_num)
ax = p3.Axes3D(fig)
# x,y,z = dataset
color = 'r'
mark = '*'
# 3D折线图
ax.scatter3D(x, y, z ,c = color, marker = mark)
# 3D曲面图
ax.plot_surface(x1, y, z ,rstride=1, cstride=1, cmap=plt.cm.hot)
plt.legend()
plt.show()
Reference
[1]. matplotlib examples