Skip to content Skip to sidebar Skip to footer

Why Are The Arguments To Matplotlib's Plot_wireframe Two Dimensional Arrays?

I cannot find a clear explanation of the X, Y, and Z arguments to Matplotlib's plot_wireframe function. I have been playing with their provided example wire3d_demo.py but I don't g

Solution 1:

In plot_wireframe(X,Y,Z), X are the x coordinates, Y are the y coordinates and Z are the z coordinates. Those need to be 2D arrays. The reason is that the plotting function needs a 2D grid. Hence, (X[i,j], Y[i,j], Z[i,j]) defines a point in cartesian space. i,j are the grid indices.

Now the question might be, why do we need i,j as grid index, and cannot use a single 1D grid with an index k alone, such that X,Y,Z would be 1D arrays? That is, because in the case of (X[k], Y[k], Z[k]) the information about which point lies next to which other point is lost. In the 2D grid, you can unambigously determine that (X[i,j], Y[i,j], Z[i,j]) is connected to (a neighbor of) (X[i+1,j], Y[i+1,j], Z[i+1,j]), as well as e.g. (X[i,j-1], Y[i,j-1], Z[i,j-1]). In the 1D case, (X[k+1], Y[k+1], Z[k+1]) is clearly connected to (X[k], Y[k], Z[k]), but that gives you only two connections, while you need 4 connections in the wireframe.

Solution 2:

Let me explain with some numbers. For each value of x, there is a range of y-values. Suppose you have total 9 points in 3-d surface. Each of them will have a x-value, a y-value and a corresponding z-value. Let's say x = 1, 2, 3 and y = 1, 2, 3.

Now for each value of x, there are 3 y-points because you have a sort of meshgrid

x = 1 --> y = 1, 2, 3x = 2 --> y = 1, 2, 3x = 3 --> y = 1, 2, 3

Similarly, for each value of y, there are 3 x-points.

y = 1 --> x = 1, 2, 3y = 2 --> x = 1, 2, 3y = 3 --> x = 1, 2, 3

So total combinations of x and y and 9

(x, y) --> (1, 1), (1, 2), (1, 3), 
           (2, 1), (2, 2), (2, 3), 
           (3, 1), (3, 2), (3, 3) 

So the shape of x-values now becomes (3x3) because you have total 9 values. Similarly the shape of y-values becomes (3x3). Now for each of these (x, y) pair, you have a corresponding z-value in 3d space. Hence, your z-values also has to be a 3x3 array.

The same concept and explanation holds for any number of points, in your question this number being 120x120.

Post a Comment for "Why Are The Arguments To Matplotlib's Plot_wireframe Two Dimensional Arrays?"