I want to plot a 3D surface in matplotlib from xy and z data. For this I need to do a seemingly simple data transformation but I am unsure on how to proceed.
My x and y data are uniform integers because it will be the surface of an image. My data is present in the form of a 512x512 numpy array. The values of the array are the z values, and the indexes are the x and y values respectively.
So if arr is my array, arr[x, y] would give my z. The form just looks like this:
z z z z ... z (512 columns)
z z z z ... z
z z z z ... z
z z z z ... z
. . . .
. . . .
z z z z (512 rows)
How do I get my data in the form of three columns x, y, z so I can do the surface plot? It should look like this after the transform:
x | y | z
---------
0 | 0 | z
1 | 0 | z
2 | 0 | z
. | . | .
. | . | .
511 | 0 | z
0 | 1 | z
1 | 1 | z
2 | 1 | z
. | . | .
. | . | .
I tried to work with np.meshgrid and np.flatten but can't get it to work the way I want. Maybe theres an even easier pandas solution to this. Or maybe I can even plot it with the original form of the data?
Any suggestion is appreciated :)