I'm trying to represent 2d arrays as a surface plot. For example, given the following data:
data = [[88873.0], [107535.0], [27428.0], [1360.0], [12310.0]]
I get the following figure:
With more data
data = [[88873.0], [107535.0], [27428.0], [1360.0], [12310.0], [0], [106113.0, 96156.0], [0], [102891.0], [21726.0]]
I get:
We can see how the curves on top are lost giving the impression of having several peaks. The more data I use, the worse it gets.
Surface plotting code:
from mpl_toolkits.mplot3d import Axes3D
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
import numpy as np
arr = data
new_arr = []
N= 2 //maximum number of values in Z
for i, sub_arr in enumerate(arr):
new_arr.append((i+1, -1, 0))
new_arr.append((i+1, N, 0))
for j, z in enumerate(sub_arr):
new_arr.append((i+1, j, z))
if (len(sub_arr) < N) & (j == N-2):
new_arr.append((i+1, j+1, 0))
x, y, z = zip(*new_arr)
z = map(float, z)
grid_x, grid_y = np.mgrid[min(x):max(x):100j, min(y):max(y):100j]
grid_z = griddata((x, y), z, (grid_x, grid_y), method='cubic')
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(grid_x, grid_y, grid_z, cmap=plt.cm.Spectral)
plt.show()
Do you know how to make a more presentable figure?