简体   繁体   中英

Python matplotlib imshow from data file

I have a 3 columns data file (xy z1 z2 z3) in which z have a value corresponding to the grid point x,y data file

I would like to create a matplotlib.pyplot.imshow from the data stored in file using z1.. I found this piece of code that does not work properly for me:

x,y,data1 = np.genfromtxt('cosrevalsjpdf.dat',usecols=(0,1,2),unpack=True,skip_header=0)
xll = x.min();  xul = x.max();  yll = y.min();  yul = y.max()
xi = np.linspace(x.min(), x.max(), 100) 
yi = np.linspace(y.min(), y.max(), 100) 
zi = scipy.interpolate.griddata((x, y), z, (xi[None,:], yi[:,None]), method='linear')

fig = plt.figure()
plt.imshow(zi, extent=[xll, xul, yll, yul], origin='lower', cmap=cm.hot, alpha=0.9)
plt.show() 

I would like to obtain a 2D contour plot full of color not like using contourf with generate a iso line.. how can I do?

using contourf as follow:

plt.contourf(xi,yi,zi,cmap=cm.hot, levels=20)

I obtain this.. that is quite good but I would like to full filled to black the white area how can I do it? 结果

Get the current axis with ax = plt.gca() , and change its color with ax.set_facecolor('black') or ax.patch.set_facecolor('black') .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM