#! /usr/bin/env python
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
#
# Assuming you have "2D" dataset like the following that you need
# to plot.
#
data_2d = [ [1,   2,  3,  4,  5,  6,  7,  8,  9, 10],
            [6,   7,  8,  9, 10, 11, 12, 13, 14, 15],
            [11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
            [16, 17, 18, 19, 20, 21, 22, 23, 24, 25],
            [21, 22, 23, 24, 25, 26, 27, 28, 29, 30] ]
#~ print 'data_2d'
#~ print data_2d

#
# Convert it into an numpy array.
#
data_array = np.array(data_2d)
#~ print 'data_array'
#~ print data_array

#
# Create a figure for plotting the data as a 3D histogram.
#
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
#
# Create an X-Y mesh of the same dimension as the 2D data. You can
# think of this as the floor of the plot.
#
x_data, y_data = np.meshgrid( np.arange(data_array.shape[1]),
                              np.arange(data_array.shape[0]) )
#~ print 'x_data;	y_data'
#~ print x_data
#~ print y_data
#
# Flatten out the arrays so that they may be passed to "ax.bar3d".
# Basically, ax.bar3d expects three one-dimensional arrays:
# x_data, y_data, z_data. The following call boils down to picking
# one entry from each array and plotting a bar to from
# (x_data[i], y_data[i], 0) to (x_data[i], y_data[i], z_data[i]).
#

guess = np.mgrid[0:1:11j, 0:0.7:8j]
#~ print'guess'
#~ print guess
#~ print'end'
#~ print 'x_data'
print guess[1].flatten()
print 'y_data'
print guess[0].flatten()

#~ guess = np.mgrid[0:5, 0:10]
#~ print guess


x_data = x_data.flatten()
y_data = y_data.flatten()
#~ print 'x_data'
#~ print x_data

#~ print guess[1].flatten()
#~ print 'y_data'
#~ print y_data
#~ print guess[0].flatten()

z_data = data_array.flatten()
#~ print 'z_data'
#~ print z_data
#
# bar3d takes:
#	1. array  - X positions 
#	2. array  - Y positions
#	3. array  - Z positions
#	4. number - width of the bar in X direction (can also be an array)
#	5. number - width of the bar in Y direction (can also be an array)
#	6. array  - height of the bar in addition to the his is width of the bar in X direction (can also be a number)
#
ax.bar3d( x_data,
          y_data,
          np.zeros_like(z_data),
          1, 1, z_data )



print len(x_data), len(z_data)
ax.set_xlabel('First Row')
ax.set_ylabel('Ummm')
ax.set_zlabel('Ups')

#~ numpy.mgrid[0:0.7:8j, 0:5]


#~ ax.bar3d( x_data,
          #~ y_data,
          #~ np.zeros(len(z_data)),
          #~ 1,
          #~ 1,
          #~ z_data,
          #~ alpha = 0.5)


#
# Finally, display the plot.
#
plt.show()