2012-03-31 6 views
1

で3Dデータをプロット - これは古い記事が削除、更新後のである -matplotlibの

は、私がmatplotlibで3Dグラフ/表面にプロットしたいの下のようなデータがあるとします。どうしたらいいですか? JouniK.Seppänenの答え@続き

enter image description here

、私はmeshgrid()を必要と考え出したが、私は私の軸データは非常に正確ではないと思います。 workingSetAxisがx軸であるとする

{ 
    "data": { 
     "Random": [ 
      [1834, 3353, 4602, 5471, 6522, 7873], 
      [2637, 8575, 8357, 10329, 9742, 10359], 
      [3648, 10602, 10667, 10751, 10666, 10552], 
      [4570, 10220, 9202, 10460, 10329, 10928], 
      [5879, 10788, 10832, 10923, 11075, 10989], 
      [6783, 11104, 10235, 10499, 11024, 10731], 
      [7074, 11097, 10222, 10613, 10508, 10767], 
      [7300, 11002, 10727, 11073, 10328, 10864]], 
     "LRU": [ 
      [123, 155, 201, 223, 296, 321], 
      [143, 590, 1046, 1566, 1924, 2434], 
      [163, 1167, 1774, 2578, 3363, 3980], 
      [182, 1172, 2259, 3038, 4200, 4907], 
      [219, 1718, 3044, 3658, 5236, 5680], 
      [709, 2263, 3588, 4551, 5262, 6197], 
      [2065, 3865, 4430, 5024, 5986, 6617], 
      [3048, 4249, 5029, 5790, 6157, 6826]], 
     "FIFO": [ 
      [180, 269, 350, 424, 580, 601], 
      [230, 906, 1446, 2009, 2408, 2902], 
      [316, 1590, 2261, 3042, 3848, 4457], 
      [473, 1664, 2781, 3542, 4764, 5398], 
      [665, 2290, 3609, 4194, 5781, 6207], 
      [1158, 2826, 4115, 5064, 5751, 6613], 
      [2457, 4375, 4974, 5471, 6464, 7077], 
      [3512, 4724, 5485, 6272, 6684, 7312]] 
    }, 
    "workingSetAxis": [2, 22, 42, 62, 82, 102, 122, 142], 
    "stabilityAxis": [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] 
} 

、及びstabilityAxis Y軸:私のような(JSON)でデータを持っている場合。私は信じて

enter image description here(FIFOデータ用)

私はExcelから得たプロットとは非常に異なっ

enter image description here

:私は

plot(jsonObj["data"]["FIFO"], jsonObj["workingSetAxis"], jsonObj["stabilityAxis"]) 

def plot(data, workingSetAxis, stabilityAxis): 
    # make axis data 
    X, Y = numpy.meshgrid(workingSetAxis, stabilityAxis) 
    Z = data 

    fig = plt.figure() 
    ax = fig.add_subplot(111, projection="3d") 
    ax.plot_wireframe(X, Y, Z) 
    plt.show() 

のような何かをしたとのようなものを得ました私の軸のデータまたは何かが間違っていますが、どちらですか?

答えて

5

、例えば、あなたのデータの転置をプロット

def plot(data, workingSetAxis, stabilityAxis): 
    # make axis data 
    X, Y = numpy.meshgrid(workingSetAxis, stabilityAxis) 
    Z = numpy.transpose(data) #<--- This is the only line I have changed. 

    fig = plt.figure() 
    ax = fig.add_subplot(111, projection="3d") 
    ax.plot_wireframe(X, Y, Z) 
    plt.show() 

を使用して試してみて、あなたの例のデータは、私に与えますプロットの後に: plot demonstrating expected output

4

this example。 Z.としてデータ値を使用し、その後、meshgridで2D配列にあなたのXとYの値を回し

+0

また、私は質問を更新しました、私はちょうど私が軸を持っていると正しい順序を確認したいと思った?画像をホバリングすると、負のx値のような賢い座標が得られることがあります。おそらく、私の声は正しい場所にありません –