How to overlay a shape file with background colour on multiple subplots

29 views
Skip to first unread message

Jerry Liu

unread,
Oct 13, 2020, 5:26:06 AM10/13/20
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
Hi,

I'm using matplotlib 1.5.0  / cartopy 0.15.1 / Iris 1.13.0 with Python 2.7.10.

I'd like to substitute the basemap and the white background colour for this  12 members panel plot with high resolution coastline shapefiles and appropriate background colour.

D1_SRFC_PTSM.png

I managed to  substitute the coarse basemap with high resolution shapefiles by simply using my own high resolution coastline shapefiles instead the default nature earth 10m coastline shapefiles, like this

Change 

plt.gca().coastlines(resolution='10m')

to

plt.gca().coastlines(resolution='SASEAN_HighRes')

But I have no idea how to fill in the back ground colour for land and sea. 

Besides high coastline shape files, there is a  tiff image available ( not sure if it's so called geo-tiff image ),  like this

Hires-coastline.png

There are two approaches I'm think of

1.  Zooming the tiff image to appropriate domain and overlaying on the data plot

2.  Plot a basemap with high resolution shapefiles and fill in appropriate background colore for land and sea, then overlay the basemap on each subplots

I googled certain examples but failed to implement on my case.  I'm new to Python and GIS plotting.  I need a little bit more detailed guide.

Wondering if any one could give certain guides on how to do it ?

Here are my codes

import iris
import iris.plot as iplt
import cartopy.io.shapereader as shpreader
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.colors as mcol
import numpy as np
 
plt.figure(figsize=(14.2, 8),dpi=DPI)
plt.gcf().subplots_adjust(hspace=0.15, wspace=0.05, top=0.9, bottom=0.1, left=0.1, right=0.9)

p_cube=iris.load_cube(fname, \
                      iris.Constraint('stratiform_rainfall_rate', realization=lambda value: True), \
                      callback=realization_metadata);

shp=shpreader.Reader(shp_file)

extent=[101.55449677,106.37399292,-1.06974983,3.50674963]
proj=ccrs.PlateCarree()

for i in range(0,mbr_num):
   mbr=mbr_range[i]
   a_cube=p_cube[i,fc,114:228,170:290]*3600
   plt.subplot(dimy,dimx,(i+1))
   cf = iplt.contourf(a_cube, cscale, norm=norm, cmap=cmap)
   plt.gca().coastlines(resolution='SASEAN_HighRes')
   title_str="member " + str(mbr)
   plt.title(title_str, fontsize=8)

plt.suptitle(PLTtitle, fontsize=14);
colorbar_axes = plt.gcf().add_axes([0.35, 0.05, 0.3, 0.03])
colorbar = plt.colorbar(cf, colorbar_axes, orientation='horizontal')
colorbar.set_label(colbar_unit)
colorbar.ax.tick_params(labelsize=6)
colorbar.ax.set_xticklabels(['0', '0.1','0.25','0.62','1.55','3.87','9.66','24.1','60.3','150.0'])
plt.savefig(img_name,bbox_inches='tight',dpi=(DPI))

Thanks for your time.
Reply all
Reply to author
Forward
0 new messages