Dường như PCOLOR đang cắt bỏ hàng và cột cuối cùng của tập dữ liệu của tôi. In hình dạng của zi
dưới đây cho thấy rằng nó là (22,22)
, như tôi mong đợi, nhưng diện tích 21 hình vuông bởi 21 hình vuông được hiển thị ... Bất kỳ ý tưởng tại sao hàng cuối cùng và cột không được vẽ?Matplotlib: pcolor() không âm mưu hàng và cột cuối cùng?
def pcolor_probs(x,y,z, x_str, y_str, t_str):
xi = np.arange(min(x),max(x)+1, 1)
yi = np.arange(min(y),max(y)+1, 1)
zi = griddata(x,y,z,xi,yi)
print np.shape(xi),np.shape(yi),np.shape(zi)
# fix NANs
zi = np.asarray(zi)
for i in range(len(zi)):
for j in range(len(zi[i])):
print i,j
if isnan(float(zi[i][j])):
zi[i][j] = 0
# plot
f = figure()
ax = f.add_subplot(111)
pc_plot = ax.pcolor(zi, cmap = cm.coolwarm, shading = 'faceted', alpha = 0.75)
# pc_plot = ax.contourf(zi, 20, cmap = cm.coolwarm, alpha = 0.75)
ax.set_xticks(np.arange(zi.shape[0])+0.5, minor=False)
ax.set_yticks(np.arange(zi.shape[1])+0.5, minor=False)
ax.set_xticklabels(np.arange(len(xi)))
ax.set_yticklabels(np.arange(len(yi)))
ax.set_xlim(min(x), max(x))
ax.set_ylim(min(y), max(y))
ax.set_xlabel(x_str)
ax.set_ylabel(y_str)
ax.set_title(t_str)
f.colorbar(pc_plot)
f.set_tight_layout(True)
font = {'family' : 'serif','weight' : 'regular','size' : 12}
matplotlib.rc('font', **font)
show()
Hãy làm cho nó thậm chí còn đơn giản hơn,
X = np.random.rand(10,10)
pcolor(X)
show()
Tạo,
Vui lòng thêm liên kết vào tài liệu pcolor. – tacaswell