Search code examples
pythonmatplotlib-basemapcontourf

Overlaying contour plot on basemap


Please can anyone look at this code it is not giving a desired result.

    # use the Miller projection
    m = Basemap( projection='mill', resolution='i', lon_0=0., lat_0=0.)
    
    # draw coastline, map-boundary
    m.drawcoastlines(linewidth=0.5)
    m.drawmapboundary( fill_color='white' )
    # draw grid 
    m.drawparallels( np.arange(-90.,90.,30.), labels=[1,0,0,0] )
    m.drawmeridians( np.arange(-180.,180.,60.), labels=[0,0,0,1] )
        # Creating 2-D grid of features
    [Lat, Lon] = np.meshgrid(lats, lons)
    pLat, pLon = m(Lat, Lon)
    # plots filled contour plot
    cfig = m.contourf(pLon, pLat, OLR_2011, levels= clevel, extend = 'both', cmap="jet")
    cbar = m.colorbar(cfig, location = 'right', pad = "10%")  
    plt.show()
      

The result is shown in this figure.

I want the overplot to cover the basemap. Please where did I go wrong.


Solution

  • When converting from lat/lon to map coordinates, Basemap takes (Lon, Lat), not (Lat, Lon).

    So you need to replace:

    pLat, pLon = m(Lat, Lon)
    

    with:

    pLon, pLat = m(Lon, Lat)