Matplotlib:pcolor() 不绘制最后一行和最后一列? [英] Matplotlib: pcolor() does not plot last row and column?

查看:30
本文介绍了Matplotlib:pcolor() 不绘制最后一行和最后一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎PCOLOR正在切断数据集的最后一行和最后一列.在下面打印 zi 的形状表明它是 (22,22),正如我所期望的,但是显示的是21平方乘21平方的面积...知道为什么不绘制最后一行和最后一列?

It seems that PCOLOR is chopping off the last row and column of my data set. Printing the shape of zi below reveals that it is (22,22), as I expect, but an area of 21 squares by 21 squares is shown... Any idea why the last row and column are not being plotted?

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()

让我们更简单,

X = np.random.rand(10,10)
pcolor(X)
show()

生产

推荐答案

原因是pcolor对顶点进行计数.实际上,有22和10个顶点.改用 imshow(...,extent []).

The reason is that pcolor counts points on vertices. There are, in fact, 22 and 10 vertices. Use imshow(...,extent[]) instead.

这篇关于Matplotlib:pcolor() 不绘制最后一行和最后一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆