matplotlib pcolormesh plot from x,y,z data

后端 未结 4 543
深忆病人
深忆病人 2021-01-06 03:03

I have data in a textfile in tableform with three columns. I use np.genfromtxt to read all the columns into matplotlib as x, y, z.

I want to create a color meshplot

4条回答
  •  太阳男子
    2021-01-06 04:05

    My guess is that x, y and z will be read as one-dimensional vectors of the same length, let's say N. The problem is that when you create your xmesh and ymesh, they are N x N, which your z values should be as well. It's only N, which is why you are getting an error.

    What is the layout of your file? I'm guessing each row is a (x,y,z) that you want to create a mesh from. In order to do this, you need to know how the points are ordered as a mesh (either as row-major or column-major). Once you know this, instead of creating xmesh and ymesh, you can do something like this:

    N = np.sqrt(len(x)) # Only if squared, adjust accordingly
    x = x.reshape((N, N))
    y = y.reshape((N, N))
    z = z.reshape((N, N))
    pcolormesh(x, y, z)
    

    Before doing this, I would start by doing this:

    scatter(x, y, c=z)
    

    which will give you the points of the mesh, which is a good starting point.

提交回复
热议问题