2017-08-07 85 views
0

在執行下面給出的代碼時,所有z座標都正確顯示,但x軸僅顯示1-10座標和y軸僅顯示s1,s2,s3,s4座標。我如何繪製這個3D曲面圖中的所有座標?Plotly 3D Surface圖不顯示所有x和y座標

var data = [{ 
 
    z: [ 
 
    [1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10], 
 
    [2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11], 
 
    [3.5, 4.5, 6.5, 7.5, 8.5, 9.5, 4.5, 3.5, 2.5, 10], 
 
    [5.5, 6.5, 7.5, 15.5, 16.5, 17.5, 18.5, 19.5, 12.5, 17] 
 
    ], 
 
    x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], 
 
    y: ['s1', 's2', 's3', 's4', 's5', 's6', 's7', 's8', 's9', 's10'], 
 
    type: 'surface' 
 
}]; 
 

 
var layout = { 
 
    title: 'Trips Overview', 
 
    scene: { 
 
    xaxis: { 
 
     title: 'Time', 
 
     titlefont: { 
 
     color: 'red', 
 
     family: 'Arial, Open Sans', 
 
     size: 12 
 
     } 
 
    }, 
 
    yaxis: { 
 
     title: 'stops', 
 
     titlefont: { 
 
     color: 'red', 
 
     family: 'Arial, Open Sans', 
 
     size: 12 
 
     } 
 
    }, 
 
    zaxis: { 
 
     title: 'trips', 
 
     titlefont: { 
 
     color: 'red', 
 
     family: 'Arial, Open Sans', 
 
     size: 12 
 
     } 
 
    } 
 
    }, 
 
    autosize: true 
 
}; 
 
Plotly.newPlot('myDiv', data, layout);
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> 
 
<div id="myDiv" style="width:100%;height:100%"></div>

回答

0

我plotly檢查表面繪製在codepen,所以對於每一個陣列中的X軸和Y軸的值的,應該有與z陣列內的相應子陣列。

E.g: 
In your code 
X axis: 1 
Y axis: "s1" 
will have the Z values as [1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10]. 

因此,您只提供了4個Z數組列表,因此我們看不到上面的「s5」。

參考:

+0

非常感謝。順便說一下,我有不等於x和y座標,我需要在三維曲面圖中針對z軸繪製它們。有沒有其他可能的方法來做到這一點? – AkshayaCB

+0

@AkshayaCB Z的缺失值可以用[13,14,0,15]或類似的[13,14,15]給出,但Z子數組的長度必須與X和Y的數組相同 –

+0

@AkshayaCB是否幫助你,這是你的問題的正確答案? –