1

I am trying to implement a SOM (self-organizing map) in anaconda 2, and my operating system is windows 10. After pouring iris dataset in, I got a array as following:

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.]])

and i want to plot a chart looks like:

Graph

I've tried any way i can find, please talk me how to do it.

pppery
  • 3,731
  • 22
  • 33
  • 46
Nia
  • 99
  • 1
  • 2
  • 6

1 Answers1

0

Try this, which is derived from 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

tfv
  • 6,016
  • 4
  • 36
  • 67
  • @ Nia: You're welcome. If solutions work, you can upvote or accept the answer. This is a way of showing others that the answer is helpful and for thanking the author for spending his time. Maybe you want to have a short look here on how to proceed if an answer works: http://stackoverflow.com/help/someone-answers Though it is polite to do so in normal life, "thank you" in comments is not really encouraged. – tfv May 05 '16 at 16:48