# And that was only for one dimension¶

## Second dimension will need 3D plots¶

### How to plot 3D histograms in python! Yay!¶

In [3]:
%matplotlib inline

In [4]:
#! /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] ]
#
# Convert it into an numpy array.
#
data_array = np.array(data_2d)
#
# Create a figure for plotting the data as a 3D histogram.
#
fig = plt.figure()
#
# 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]) )
#
# 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]).
#
x_data = x_data.flatten()
y_data = y_data.flatten()
z_data = data_array.flatten()
ax.bar3d( x_data,
y_data,
np.zeros(len(z_data)),
1, 1, z_data )
#
# Finally, display the plot.
#
plt.show()


squareGridMatrix[n_] := Table[Table[ If [(j == i + 1 && Quotient[j - 1, n] == Quotient[i - 1, n]) || (j == i - 1 && Quotient[j - 1, n] == Quotient[i - 1, n]) || j == i - n || j == i + n, 1, 0], {j, n^2}], {i, n^2}]

In [18]:
import numpy as np

def square_grid_matrix(n):
adjacency_matrix = np.zeros((n * n, n * n))
for i in range(n ** 2):
for j in range(n ** 2):
if j == i + 1 and j // n == i // n:
elif j == i - 1 and j // n == i // n:
elif j == i + n:
elif j == i - n:
print(markov_matrix)

In [19]:
square_grid_matrix(3)

[[ 0.    0.25  0.    0.25  0.    0.    0.    0.    0.  ]
[ 0.25  0.    0.25  0.    0.25  0.    0.    0.    0.  ]
[ 0.    0.25  0.    0.    0.    0.25  0.    0.    0.  ]
[ 0.25  0.    0.    0.    0.25  0.    0.25  0.    0.  ]
[ 0.    0.25  0.    0.25  0.    0.25  0.    0.25  0.  ]
[ 0.    0.    0.25  0.    0.25  0.    0.    0.    0.25]
[ 0.    0.    0.    0.25  0.    0.    0.    0.25  0.  ]
[ 0.    0.    0.    0.    0.25  0.    0.25  0.    0.25]
[ 0.    0.    0.    0.    0.    0.25  0.    0.25  0.  ]]

In [9]:


Out[9]:
1
In [ ]: