Mathematica 3D plot with x and y axis coordinates in separate lists

I have a size matrix (ixj) mat that contains values ​​from an experiment.

If I use ListPlot3D[mat] , I can visualize this in 3D graphics.

I also have two arrays of size i ( aRow ) and size j ( aCol ), which I determined from my experiment.

How to replace the default x and y axes shown by ListPlot3D[mat] with aRow and aCol ?

+4
source share
2 answers

Pay attention to the Ticks parameter, and this example is used in documents.


Here is one way to do it. First create some sample data:

 mat = Table[Exp[-(x^2 + y^2)], {x, -2, 2, .1}, {y, -2, 2, .1}]; aCol = aRow = Round[mat[[20]], 0.01]; 

Place it in 3D. I decided to show every tenth mark of all possible. list[[;; ;; 10]] list[[;; ;; 10]] selects every 10th element of the list.

 ListPlot3D[mat, Ticks -> { Transpose[{ Range@Length [aRow], aRow}][[;; ;; 10]], Transpose[{ Range@Length [aCol], aCol}][[;; ;; 10]], Automatic}] 

Mathematica graphics

Plan it in 2D. ListDensityPlot has Frame (not Axes ) by default, so we use FrameTicks

 ListDensityPlot[mat, FrameTicks -> { Transpose[{ Range@Length [aRow], aRow}][[;; ;; 10]], Transpose[{ Range@Length [aCol], aCol}][[;; ;; 10]], None, None}, Mesh -> Automatic] 

Mathematica graphics


Update

If you don’t need arbitrary ticks, just a different range for regular labels with linear spaces, you can use the DataRange parameter as follows:

 ListPlot3D[mat, DataRange -> {{0, 1}, {0, 1}}] 

Mathematica graphics

If you still need data in the format {x,y,z} (since the coordinates are not evenly distributed), you can create it with

 Join @@ MapThread[Append, {Outer[List, aRow, aCol], mat}, 2] 
+3
source

If the differences between consecutive elements in aRow and bRow constant, you can do something like

 ListPlot3D[mat, DataRange -> (Through[{Min, Max}[#]] & /@ {aCol, aRow})] 

If not, then you can create a list with the elements {aCol[[i]], aRow[[j]], mat[[j,i]]} and build it. There are different ways to do this, for example

 list = Flatten[Table[{aCol[[i]], aRow[[j]], mat[[j, i]]}, {i, Length[aCol]}, {j, Length[aRow]}], 1]; ListPlot3D[list] 

Edit

A faster way to create a list is to do something like

 list = ConstantArray[0, {Length[aCol] Length[aRow], 3}]; list[[All, {2, 1}]] = Tuples[{aRow, aCol}]; list[[All, 3]] = Flatten[mat]; 
+2
source

Source: https://habr.com/ru/post/1389260/


All Articles