Pregunta

I've made a plot using matplotlib, it can visualise my data, but to add some more detail I would like to fill the continents with one colour so people can distinguish land from ocean.

But if I add all of this together, than always the fillcontinents is drawn on top, making my data disappear. I can change the alpha and my plot appears again, but this makes the colours of my plot different.

I've seen maps where people made it right with some point data, but I can't get it with my map. My code:

m = Basemap(projection='merc',llcrnrlon=extent[0],
            llcrnrlat=extent[3],urcrnrlon=extent[1],
            urcrnrlat=extent[2], resolution='h', lat_0=lat_mid,
            lon_0=extent[0])

# annotate
m.readshapefile(ShapefileCoastlines, 'coastlines', drawbounds=True, linewidth=0.2, color='0.1')
m.readshapefile(ShapefileCountry, 'country', drawbounds=True, linewidth=0.2, color='0.1' )
m.fillcontinents(color='coral', lake_color='aqua')
m.drawmeridians(np.arange(0,360,15), linewidth=.2, labels=[1,0,0,1], labelstyle='+/-', color='grey' ) 
m.drawparallels(np.arange(-90,90,15), linewidth=.2, labels=[1,0,0,1], labelstyle='+/-', color='grey')
m.drawmapboundary(linewidth=0.5, color='grey')

# plot data
im1 = m.pcolormesh(xx, yy, data.T, cmap=cmap, norm=norm) 
m.colorbar(im1, location='bottom', cmap=cmap, norm=norm, ticks=[-1]+bounds+[1], pad = '6%', extend='both', extendfrac='auto').set_label('units')
¿Fue útil?

Solución 2

I was able to solve it quickly using Cartopy. Here I could add an OCEAN feature instead of the LAND feature (which also in Cartopy is drawn on top of the data). Which gives the same effect.

Finally would add that Cartopy is a very powerful module and worthwhile trying coming from the pains of Basemap

Otros consejos

I saw somewhere, try using zorder = 4 in your pcolormesh command.

Best

You can use m.drawlsmask, it will not cover your plot.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top