python中的二维地图平滑

2024-10-03 11:22:43 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法平滑二维地图?这是我得到的enter image description here,我想把它弄平。测量步骤太大了,结果是这样的“坏”光谱。。。在

以下是我的部分代码:

    X, Y = np.meshgrid(x,y)
    fig, ax = plt.subplots()
    plt.xlim(235,420)
    plt.xticks(np.arange(235,415,30))
    plt.yticks(np.arange(0,360,50))
    cs = ax.pcolormesh(X,Y,A,cmap=cm.rainbow, vmin = 0)#Greys_r
    plt.xlabel('wavelength [nm]')
    plt.ylabel('temperature [K]')
    plt.title(sample)
    cbar = fig.colorbar(cs)
    cbar.formatter.set_powerlimits((0, 0))
    cbar.update_ticks()

Tags: 代码np地图fig步骤plt光谱ax
1条回答
网友
1楼 · 发布于 2024-10-03 11:22:43

我找到了一个办法。方法如下:

    fig = plt.figure()
    ax = fig.add_subplot(111)
    im = NonUniformImage(ax, interpolation='bilinear', extent=(180, 300, 10, 350), cmap=cm.jet)
    im.set_data(x, y, A)
    ax.images.append(im)
    ax.set_xlim(180, 300)
    ax.set_ylim(10, 350)
    plt.xlabel('wavelength [nm]')
    plt.ylabel('temperature [K]')
    plt.title(sample)
    cbar = fig.colorbar(im)
    cbar.formatter.set_powerlimits((0, 0))
    cbar.update_ticks()
    plt.savefig('map.png')
    plt.show()
    plt.close()

相关问题 更多 >