How to visualize scalar 2D data with Matplotlib?

前端 未结 4 995
梦谈多话
梦谈多话 2021-02-08 10:17

So i have a meshgrid (matrices X and Y) together with scalar data (matrix Z), and i need to visualize this. Preferably some 2D image with colors at the points showing the value

4条回答
  •  死守一世寂寞
    2021-02-08 11:03

    If your meshgrid has uniform spacing, you could continue to use pcolor, but just shift X and Y for the purposes of centering the data at the particular values rather than at the corners.

    You could also use a scatter plot to explicitly place points of some size at the exact X and Y points and then set the color to Z:

    x = numpy.arange(10)
    y = numpy.arange(10)
    X,Y = numpy.meshgrid(x,y)
    Z = numpy.arange(100).reshape((10,10))
    scatter(X,Y,c=Z,marker='s',s=1500) 
    #I picked a marker size that basically overlapped the symbols at the edges
    axis('equal')
    

    or:

    pcolor(X+0.5,Y+0.5,Z)
    axis('equal')
    

    or as Paul suggested, using one of the contour functions

提交回复
热议问题