I have some 3D data e.g. d=[x, y, z, f]
where z is a column of numbers in Z, used as color information.
f is a flag which is
- 0 if
xandyhave some specific values (ugly^^) - 1 if
xandyare ok
So for the good data d[ d[:,3] == 1 ] I want to generate a profile
plt.imshow(resampled.T, extent=extent, vmin=MIN, vmax=MAX, origin='lower')
and for the ugly data d[ d[:,3] == 0 ] I want to just use a specific color, e.g. black
Is there a way to realize that?
EDIT: Combining the comments of @eumiro and @Rutger Kassies, I have now the following result

Which is satisfying I think.
For the sake of completeness (or maybe there are some optimization I’m not aware of^^), here is the code and the data:
import numpy as np
from matplotlib.mlab import griddata
import matplotlib
import matplotlib.pyplot as plt
def plotprofile(x, y, z0, name='dummy', save=1):
#plt.figure()
N = 50j
z = z0[:,0]
extent = (min(x), max(x), min(y), max(y))
xs,ys = np.mgrid[extent[0]:extent[1]:N, extent[2]:extent[3]:N]
resampled = griddata(x, y, z, xs, ys)
cmap = plt.get_cmap()
cmap.set_bad(color = 'k', alpha = 1.)
#plt.imshow(resampled.T, cmap='Greys', extent=extent, origin='lower', interpolation='spline36')
plt.imshow(resampled.T, cmap=cmap, extent=extent, origin='lower', vmin=min(z), vmax=-min(z),interpolation='spline36')
cbar=plt.colorbar()
s=20
plt.ylabel(r"$y$", size=s)
plt.xlabel(r"$x", size=s)
plt.xlim([x.min(),x.max()])
plt.ylim([y.min(),y.max()])
if save:
for end in ["pdf", "png", "eps"]:
print "save %s.%s"%(name,end)
plt.savefig("%s.%s"%(name,end))
else:
plt.show()
plt.clf()
if __name__ == '__main__':
filename = 'data.txt'
data = np.loadtxt(filename)
x = data[:,0]
y = data[:,1]
z = data[:,3:]
plotprofile(x, y, z, 'dummy', 0)
Can’t you create just a normal colourmap in z by using f to mask z?
Then convert to an image like this:
Now you should be able to plot
Zlike a normal image or as a surface against[X, Y]