2

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:

enter image description here

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:

enter image description here

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?

Rafael Angarita
  • 777
  • 10
  • 27
  • This would be easier to answer if we could run the code and produce the plot. Is it not possible to generate some sample data which produces a similar problem? – tom10 May 05 '15 at 14:49
  • @tom10 I think you can run it with the two arrays of my example data = [[88873.0], [107535.0], [27428.0], [1360.0], [12310.0]] and the other one. – Rafael Angarita May 06 '15 at 08:47

0 Answers0