Search code examples
pythonsmoothing

Smoothing 2D map in python


is there any way to smooth 2D map? Here is what I have got enter image description here and I would like to smooth it. Measurement step was to big which results with such "bad" spectrum...

Here is a part of my code:

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

Solution

  • I found a way to do it. Here is how:

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