On Tue, Dec 13, 2011 at 1:12 PM, Martella, C. <c.martella@...> wrote:
> Hello,
>
> I have 2D array where each (x, y) cell represents the height of that point
> on the Z axis (you can think of it as the map of some mountain chain).
> I'd like to get the plot_surface() of this data. What I don't understand
> in particular is the content of the X, Y ,Z array parameter in my
> particular example.
>
> Can anybody elaborate on this please?
>
>
Claudio,
X and Y represent the coordinates of the height data (which is Z). X and Y
must be the same shape as the Z data. For example:
# Create 1D coordinate arrays
x = np.arange(10, 10, 0.5) # length 40
y = np.arange(25, 25, 2.5) # length 20
# Create 2D arrays from the coordinate arrays
# The shape of X and Y will be (20, 40)
# i.e., 20 rows and 40 columns.
X, Y = np.meshgrid(x, y)
# This will also have shape of (20, 40)
Z = np.sqrt(X**2 + Y**2)
ax.plot_surface(X, Y, Z)
Now, a more complicated example shows that the X and Y coordinates do not
have to be monotonic, but the coordinates must be neighboring in both
euclidean space and in the data array, or else the surface will look
"torn". This example on the website shows how to plot a sphere by using a
parametric representation of the surface:
http://matplotlib.sourceforge.net/examples/mplot3d/surface3d_demo2.html
I hope this helps!
Ben Root
