OK, there's a few steps to this.
First, a much simpler way to read your data file is with numpy.genfromtxt
. You can set the delimiter to be a comma with the delimiter
argument.
Next, we want to make a 2D mesh of x
and y
, so we need to just store the unique values from those to arrays to feed to numpy.meshgrid
.
Finally, we can use the length of those two arrays to reshape our z
array.
(NOTE: This method assumes you have a regular grid, with an x
, y
and z
for every point on the grid).
For example:
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt('eye_.txt',delimiter=',')
x=data[:,0]
y=data[:,1]
z=data[:,2]
## Equivalently, we could do that all in one line with:
# x,y,z = np.genfromtxt('eye_.txt', delimiter=',', usecols=(0,1,2))
x=np.unique(x)
y=np.unique(y)
X,Y = np.meshgrid(x,y)
Z=z.reshape(len(y),len(x))
plt.pcolormesh(X,Y,Z)
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…