2012-01-04 170 views
4

我有一個(i x j)大小的矩陣mat其中包含實驗的值。Mathematica三維座標在單獨的列表中的x和y軸座標

如果我使用ListPlot3D[mat]我可以在3D圖中看到它。

我還有兩個大小爲i(aRow)的數組和j(aCol),這是我從我的實驗中確定的。

如何將ListPlot3D[mat]所示的默認x軸和y軸替換爲aRowaCol

回答

3

請查看Ticks選項,它在文檔中使用示例。


下面介紹一種方法。首先生成一些示例數據:

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

以3D繪圖。我選擇了顯示所有可能的第10個刻度線。 list[[;; ;; 10]]選擇列表的每10個元素。

ListPlot3D[mat, 
Ticks -> { 
    Transpose[{[email protected][aRow], aRow}][[;; ;; 10]], 
    Transpose[{[email protected][aCol], aCol}][[;; ;; 10]], 
    Automatic}] 

Mathematica graphics

繪製它在2D太多。 ListDensityPlotFrame(不Axes)默認情況下,所以我們使用FrameTicks

ListDensityPlot[mat, 
FrameTicks -> { 
    Transpose[{[email protected][aRow], aRow}][[;; ;; 10]], 
    Transpose[{[email protected][aCol], aCol}][[;; ;; 10]], 
    None, None}, 
Mesh -> Automatic] 

Mathematica graphics


更新

如果您不需要任意蜱,只是不同的範圍對於通常的線性空格刻度標記,則可以使用DataRange這樣的選項:

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

Mathematica graphics

如果您仍需要一個{x,y,z}格式的數據(因爲座標不是均勻分佈的),你可以使用

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

這是很好的,但是我會控制根據默認情況下的滴答間隔,我將不使用滴答。 – akk 2012-01-04 12:15:28

+0

我認爲這可以通過以某種方式對數據本身使用「移調」命令來完成。編輯:我的意思是移調 – akk 2012-01-04 12:20:31

+0

@akk據我所知,沒有辦法檢索自動生成的刻度標記('AbsoluteOptions [graphics,T​​icks]'''Automatic'')。我記得很久以前就試圖做到這一點,但我失敗了。你必須想出你自己的算法來找到一個tick密度。 – Szabolcs 2012-01-04 12:25:50

2

如果在連續元素之間的差異構建它aRowbRow是恆定的,你可以做類似

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

如果沒有,那麼你可以創建一個元素列表{aCol[[i]], aRow[[j]], mat[[j,i]]}並繪製它。有不同的方式來做到這一點,例如

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

ListPlot3D[list] 

編輯

一個更快的方法來創建list是做這樣的事情

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