The term overlay plot means that on top of one plot a second plot (or more) is drawn. In most cases the so called base plot shows one variable and the overlayed plot shows another variable with another plot type. </br></br> The following example demonstrates how to overlay a contour line plot showing the variable relative humidity on top of the contour fill plot showing the variable temperature which is also a map plot.
Open the file which is included in the NCL package and read the variables t and rhumidity.
In [1]:
f = addfile("$NCARG_ROOT/lib/ncarg/data/nug/rectilinear_grid_3D.nc","r")
temp = f->t
rhum = f->rhumidity
Send graphic output to PNG files plot_overlay.000001.png, plot_overlay.000002.png, ...
In [2]:
wks_type = "png"
wks_type@wkWidth = 400
wks_type@wkHeight = 400
wks = gsn_open_wks(wks_type,"plot_overlay")
Set plot resources for variable temp.
In [3]:
rest = True
rest@gsnDraw = False ;-- draw only in memory
rest@gsnFrame = False ;-- don't advance the frame
rest@gsnMaximize = True
rest@cnFillOn = True
rest@cnFillPalette = "cmp_b2r"
rest@cnLinesOn = False
For a better visbility make the map outlines thicker and change the color to dark gray.
In [4]:
rest@mpGeophysicalLineColor = "gray10"
rest@mpGeophysicalLineThicknessF = 2.
Select a sub-region that we can see the contour lines better.
In [5]:
rest@mpMinLatF = 30.
rest@mpMaxLatF = 80.
rest@mpMinLonF = -15.
rest@mpMaxLonF = 60.
Create the contour fill plot of variable temp on a map.
In [6]:
plot_temp = gsn_csm_contour_map(wks,temp(0,0,:,:),rest)
Set plot resources for variable rhum.
In [7]:
resr = True
resr@gsnDraw = False ;-- draw only in memory
resr@gsnFrame = False ;-- don't advance the frame
resr@gsnMaximize = True
Create the contour line plot of variable rhum. Note: don't use _map here
In [8]:
plot_rhum = gsn_csm_contour(wks,rhum(0,0,:,:),resr) ;-- don't use _map here!
Overlay of plot_rhum onto plot_temp.
In [9]:
overlay(plot_temp, plot_rhum)
Draw the plot plot_temp and advance the frame.
In [10]:
draw(plot_temp)
frame(wks)
This representation is not very good because the map outlines and the contour lines are very similar. We need to set some additional resources for contour line color, style and thickness. Furthermore, we want to change the contour line minimum, maximum and interval.
Show minimum and maximum value of variable rhum.
In [11]:
printMinMax(rhum,0)
Set the minimum, maximum and interval for the contour lines.
In [12]:
resr@cnLevelSelectionMode = "ManualLevels" ;-- use manual contour line levels
resr@cnMinLevelValF = -0.15
resr@cnMaxLevelValF = 1.25
resr@cnLevelSpacingF = 0.1
Set line label color, background color, size, and interval. Use different dash pattern for contour lines and change the contour line color and thickness.
In [13]:
resr@cnLineLabelBackgroundColor = -1
resr@cnLineLabelFormat = "0@;*.2f"
resr@cnMonoLevelFlag = False
resr@cnLineLabelInterval = 1
resr@cnLineLabelFontHeightF = 0.010
resr@cnLineLabelFontColor = "black"
resr@cnMonoLineDashPattern = False
resr@cnLineColor = "red"
resr@cnLineThicknessF = 2.
Create a new contour fill plot as base plot. Note: normaly you can just overwrite the plot_temp object but the Jupyter notebook NCL Kernel would do something strange.
In [14]:
plot_temp2 = gsn_csm_contour_map(wks,temp(0,0,:,:),rest)
Create new contour line plot of variable rhum using the changed resources. Note: normaly you can just overwrite the plot_rhum object but the Jupyter notebook NCL Kernel would do something strange.
In [15]:
plot_rhum2 = gsn_csm_contour(wks,rhum(0,0,:,:),resr)
Overlay of plot_rhum onto plot_temp.
In [16]:
overlay(plot_temp2, plot_rhum2)
Draw the plot plot_temp and advance the frame.
In [17]:
draw(plot_temp2)
frame(wks)