如何从频率数组绘制表面图表

时间:2016-05-04 20:49:45

标签: python plot 3d som

我正在尝试在anaconda 2中实现SOM(自组织映射),我的操作系统是windows 10。 在输入虹膜数据集之后,我得到了如下数组:

matrix([[  3.,   6.,   4.,   0.,  10.],
    [  1.,   9.,   4.,  18.,  13.],
    [  5.,   6.,   4.,   1.,   0.],
    [  5.,   5.,   6.,   3.,   3.],
    [ 19.,   9.,   6.,   5.,   5.]])

我希望绘制一个图表:

Graph

我已经尝试过任何我能找到的方式,请告诉我该怎么做。

1 个答案:

答案 0 :(得分:0)

试试这个,它来自http://matplotlib.org/examples/mplot3d/surface3d_demo.html

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(0, 5)
Y = np.arange(0, 5)
X, Y = np.meshgrid(X, Y)
Z = [[  3.,   6.,   4.,   0.,  10.],
    [  1.,   9.,   4.,  18.,  13.],
    [  5.,   6.,   4.,   1.,   0.],
    [  5.,   5.,   6.,   3.,   3.],
    [ 19.,   9.,   6.,   5.,   5.]]

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)
ax.set_zlim(0, 20)

ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

fig.colorbar(surf, shrink=0.5, aspect=5)

plt.show()

enter image description here