Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## matplotlib-users

 [Matplotlib-users] plotting 3D From: Martella, C. - 2011-12-13 19:12:28 ```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? Thanks! Claudio -- Claudio Martella claudio.martella@... ```
 Re: [Matplotlib-users] plotting 3D From: Benjamin Root - 2011-12-15 15:58:46 Attachments: Message as HTML ```On Tue, Dec 13, 2011 at 1:12 PM, Martella, C. 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 1-D coordinate arrays x = np.arange(-10, 10, 0.5) # length 40 y = np.arange(-25, 25, 2.5) # length 20 # Create 2-D 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 ```