Generating a heat map using 3D data in matplotlib

后端 未结 1 1999
既然无缘
既然无缘 2021-01-05 22:33

I have a function returnValuesAtTime that returns three lists-x_vals,y_vals and swe_vals. All three lists are of the same

1条回答
  •  离开以前
    2021-01-05 23:19

    It looks like if reshape x, y, z to square matrix, you can do a contourf plot:

    In [7]:X
    Out[7]:
    array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
    
    In [8]:Y
    Out[8]:
    array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
           [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
           [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
           [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
           [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
           [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
           [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
           [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],
           [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]])
    
    plt.contourf(X,Y,np.random.random((10,10))) #reshape Z too!
    plt.colorbar()
    

    enter image description here

    0 讨论(0)
提交回复
热议问题