Plotting 3D surface in python
<p>Although there are several sources on how to plot 3D surfaces with XYZ format. I have a CSV file from a scanning laser that provides no coordinate information on X and Y, just Z coordinates of a rectangular grid.</p>

<p>The file is 800 x 1600 with just z coordinates. Excel can plot it very easily with surface plot, but is limited by size.</p>

<p>How can I approach this problem?</p>

<p><a href="http://i.stack.imgur.com/zSemc.png" rel="nofollow">Screenshot of data format</a></p>

<p>You just need to create arrays of the <code>X</code> and <code>Y</code> coordinates. We can do this with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html" rel="nofollow"><code>numpy.meshgrid</code></a>. In the example below, I set the cell size to 1., but you can easily scale that by changing the <code>cellsize</code> variable.</p>

<pre><code>import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

# dummy data
nx, ny = 800, 1600
Z = np.random.rand(nx, ny)

# Create x, y coords
cellsize = 1.
x = np.arange(0., float(nx), 1.) * cellsize
y = np.arange(0., float(ny), 1.) * cellsize
X, Y = np.meshgrid(x, y)

# Create matplotlib Figure and Axes
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Plot the surface
ax.plot_surface(X, Y, Z)

plt.show()
</code></pre>

python matplotlib plot surface