Re: ListPlot3D
- To: mathgroup at smc.vnet.net
- Subject: [mg131199] Re: ListPlot3D
- From: "djmpark" <djmpark at comcast.net>
- Date: Mon, 17 Jun 2013 06:25:51 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <4592512.36124.1371374283422.JavaMail.root@m06>
I'll just discuss the first example. For that the entries in the array are the z values. The coordinates of each z value are the row and column position indices in the matrix. However if we use the DataRange Option when plotting then the displayed x and y values will correspond to the DataRange values, which is usually what we want. This is a difficult plot command for beginners or people who do not often use it. One has to figure it out each time. The maxim that if a command is difficult to explain then it may be ill-designed may apply here. The confusion is that the form of the matrix is not the same as that normally produced by the Table statement with the x iterator first and the y iterator second, nor that used in the Plot3D statement that uses the same iterator order. Nor does it correspond to the values in the plot if you view it from above. (It corresponds to the plot arrangement if you view it from below.) It all depends on whether you want the plot to look like what you would consider to be the function, or what you consider to be a specific matrix. As an example let's take a nonsymmetrical array so we can distinguish x and y variation. array1 = Table[x y, {x, 0, 4}, {y, -2, 2}]; The following three displays show various forms of the matrix with row and column labels: 1) The array as it would be produced by a Table command with x and y iterators in that order. 2) The transpose of the original array. 3) The transpose of the original array with the rows reversed. This corresponds to looking at the plot from above. Grid[{{"x\\y", -2, -1, 0, 1, 2}, {0, 0, 0, 0, 0, 0}, {1, -2, -1, 0, 1, 2}, {2, -4, -2, 0, 2, 4}, {3, -6, -3, 0, 3, 6}, {4, -8, -4, 0, 4, 8}}, Dividers -> {{2 -> GrayLevel[0]}, {2 -> GrayLevel[0]}}, Spacings -> {{None, {}}, {None, {}}}, Background -> {{}, {}, {}}, Frame -> {{}, {}, {}}, ItemStyle -> {{}, {}, {}}, ItemSize -> {{Automatic, {}}, {Automatic, {}}}, Alignment -> {{Right, {}}, {Center, {}}, {}}, BaseStyle -> {14, Plain, FontFamily -> "Times"}] Grid[{{"y\\x", 0, 1, 2, 3, 4}, {-2, 0, -2, -4, -6, -8}, {-1, 0, -1, -2, -3, -4}, {0, 0, 0, 0, 0, 0}, {1, 0, 1, 2, 3, 4}, {2, 0, 2, 4, 6, 8}}, Dividers -> {{2 -> GrayLevel[0]}, {2 -> GrayLevel[0]}}, Spacings -> {{None, {}}, {None, {}}}, Background -> {{}, {}, {}}, Frame -> {{}, {}, {}}, ItemStyle -> {{}, {}, {}}, ItemSize -> {{Automatic, {}}, {Automatic, {}}}, Alignment -> {{Right, {}}, {Center, {}}, {}}, BaseStyle -> {14, Plain, FontFamily -> "Times"}] Grid[{{"y\\x", 0, 1, 2, 3, 4}, {2, 0, 2, 4, 6, 8}, {1, 0, 1, 2, 3, 4}, {0, 0, 0, 0, 0, 0}, {-1, 0, -1, -2, -3, -4}, {-2, 0, -2, -4, -6, -8}}, Dividers -> {{2 -> GrayLevel[0]}, {2 -> GrayLevel[0]}}, Spacings -> {{None, {}}, {None, {}}}, Background -> {{}, {}, {}}, Frame -> {{}, {}, {}}, ItemStyle -> {{}, {}, {}}, ItemSize -> {{Automatic, {}}, {Automatic, {}}}, Alignment -> {{Right, {}}, {Center, {}}, {}}, BaseStyle -> {14, Plain, FontFamily -> "Times"}] ListPlot3D and ListDensityPlot require the Transpose of the array as it would be produced by Table. ListPlot3D[array1 // Transpose, InterpolationOrder -> 2, Mesh -> 4, DataRange -> {{0, 4}, {-2, 2}}, AxesLabel -> {x, y, z}, BoxRatios -> {1, 1, 3/4}] ListDensityPlot[array1 // Transpose, DataRange -> {{0, 4}, {-2, 2}}, ColorFunctionScaling -> False, ColorFunction -> (ColorData["SolarColors"][Rescale[#, {-8, 8}]] &), Frame -> True, FrameTicks -> True] Plot3D requires the same iterator order as Table, i.e. it corresponds to the original array. Plot3D[x y, {x, 0, 4}, {y, -2, 2}, Mesh -> 4, BoxRatios -> {1, 1, 3/4}] But an ArrayPlot requires the third form of matrix if we want it to correspond to the other two plots. (But I suppose one would usually want an ArrayPlot to correspond to a specific matrix and not a function.) ArrayPlot[array1 // Transpose // Reverse, DataRange -> {{0, 4}, {-2, 2}}, ColorFunctionScaling -> False, ColorFunction -> (ColorData["SolarColors"][Rescale[#, {-8, 8}]] &), Frame -> True, FrameTicks -> True] And if we want the ListPlot3D to look like the original matrix we would use: ListPlot3D[array1 // Reverse, InterpolationOrder -> 2, Mesh -> 4, DataRange -> Reverse[{{0, 4}, {-2, 2}}], AxesLabel -> {y, x, z}, BoxRatios -> {1, 1, 3/4}, ViewPoint -> {1/2, -2, 0.5} 5] Got that? David Park djmpark at comcast.net http://home.comcast.net/~djmpark/index.html From: amannucci [mailto:Anthony.J.Mannucci at jpl.nasa.gov] I could use some help with ListPlot3D. These are examples from the documentation. My preconceived notion of what this should do is place a data point at coordinates {x,y,z} and connect a surface along the z_i. Here is an example from the Mathematica documentation: ListPlot3D[{{1, 1, 1, 1}, {1, 2, 1, 2}, {1, 1, 3, 1}, {1, 2, 1, 4}}, Mesh -> All] I cannot figure out how to read these data. What are the x,y values? They are apparently "the x and y coordinate values for each data point to be successive integers starting at 1." How does this thread through the data? For the first point, x=1, y=1, z=1. For the last point, x=4,y=4, z= 4. What about intermediate points? I can't figure it out. Is it x=1, y= 1..4, x=2,y=1..4,x=3,y=1..4,x=4,y=1..4? The documentation does not say. There is also the data triplets. E.g. from the documentation, ListPlot3D[{{0, 0, 1}, {1, 0, 0}, {0, 1, 0}}, Mesh -> All] This I understand. It is a triplet of {x,y,z}. However, when I feed in the following data set, the graph is completely blank: {{0., 0., 0.}, {0.1, 0.1, 0.248514}, {0.2, 0.2, 0.329812}, {0.3, 0.3, 0.324989}, {0.4, 0.4, 0.275382}, {0.5, 0.5, 0.207606}, {0.6, 0.6, 0.138975}, {0.7, 0.7, 0.0799098}, {0.8, 0.8, 0.0358315}, {0.9, 0.9, 0.008981}, {1., 1., 0.}} x and y span 0->1. There are z-values, but nothing is plotted. If I manually change the first three data points to be (mimicing the docs): {0., 0., 0.}, {1.0, 0.0, 0.248514}, {0., 1., 0.329812} I then see a surface. I cannot figure this out. Thanks for any help you can provide.