matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
774 stars 392 forks source link

Draw Basemap above xarray plot #516

Closed ghost closed 2 years ago

ghost commented 3 years ago

The Issue

I have a xarray dataset clip_ds and have visualised the data array using plot. Now, I want to add a country boundary using Basemap's drawcountries(). Apparently, there is something wrong with the extent I am using in basemap (I guess), but both the country border and the data plot won't show up together. I have tried interchanging the position of clip_ds.pr[0].plot() before and after I create basemap, and it gives me two different results: 1) This one is when I use xarray plot before basemap. Note that the colorbar from xarray is still there. Before 2) This is when I use xarray plot after basemap. The tick labels disappears in this case probably overlapped by the basemap box. After 3) The Xarray plot only looks like this. only

Code I have used

map=Basemap(projection='merc',     
               resolution='l',
               llcrnrlon=clip_ds.lon[0],
               llcrnrlat=clip_ds.lat[0],
               urcrnrlon=clip_ds.lon[-1],
               urcrnrlat=clip_ds.lat[-1])
map.drawcountries()
clip_ds.pr[0].plot()
plt.show()