Skip to content

Commit

Permalink
change cmap for scatter plot
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-hoo committed Jun 4, 2024
1 parent 3f79d91 commit a56455d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion parm/templates/template.plot_hofx.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
hofx_files: 'INPUTFP'
field_var: 'XXFIELDVAR'
field_range: [-100,100]
field_range: [XXFRLOW,XXFRHIGH]
nbins: XXNBINS
plottype: 'XXPLOTTYPE'
title_fig: 'XXFIGTITLE'
Expand Down
5 changes: 5 additions & 0 deletions scripts/exlandda_plot_stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ cp ${PARMlandda}/templates/template.plot_hofx.yaml plot_hofx.yaml
INPUTFP="${DATA_HOFX}"
# Field variable
FIELDVAR="OMA"
# Field Range: [Low,High]
FRLOW=-100
FRHIGH=100
#
NBINS=100
# Plot type (scatter/histogram/both)
Expand All @@ -23,6 +26,8 @@ PREOUTFN="hofx_oma_${PDY}"

sed -i "s|INPUTFP|${INPUTFP}|g" plot_hofx.yaml
sed -i -e "s/XXFIELDVAR/${FIELDVAR}/g" plot_hofx.yaml
sed -i -e "s/XXFRLOW/${FRLOW}/g" plot_hofx.yaml
sed -i -e "s/XXFRHIGH/${FRHIGH}/g" plot_hofx.yaml
sed -i -e "s/XXNBINS/${NBINS}/g" plot_hofx.yaml
sed -i -e "s/XXPLOTTYPE/${PLOTTYPE}/g" plot_hofx.yaml
sed -i -e "s/XXFIGTITLE/${FIGTITLE}/g" plot_hofx.yaml
Expand Down
18 changes: 14 additions & 4 deletions ush/hofx_analysis_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import cartopy.crs as ccrs
import xarray as xr
import matplotlib.ticker
import matplotlib as mpl
from matplotlib.colors import ListedColormap

def get_obs_stats(fdir, plottype):
global lat,lon
Expand Down Expand Up @@ -63,31 +65,39 @@ def plot_scatter():
print("===== PLOT: SCATTER =====")
field_mean = float("{:.2f}".format(np.mean(np.absolute(field))))
field_std = float("{:.2f}".format(np.std(np.absolute(field))))
print("Mean |OMA|=",field_mean)
print("STDV |OMA|=",field_std)
crs = ccrs.PlateCarree()
fig = plt.figure(figsize=(8,5))
ax = plt.subplot(111, projection=crs)
ax.coastlines(resolution='110m')
colors = ['red','red','red','blue','red','blue']
num_cmap = 20
cmap_neg = mpl.colormaps['Blues'].resampled(num_cmap)
cmap_pos = mpl.colormaps['Reds_r'].resampled(num_cmap)
cmap_color = np.vstack((cmap_neg(np.linspace(0,1,num_cmap)),cmap_pos(np.linspace(0,1,num_cmap))))
cmap_new = ListedColormap(cmap_color, name='BlueRed_rc')
norm = plt.Normalize(yaml_data['field_range'][0],yaml_data['field_range'][1])
sc = ax.scatter(lon, lat, c=field, s=2.0, cmap='bwr', transform=crs, norm=norm)
sc = ax.scatter(lon, lat, c=field, s=1.5, cmap=cmap_new, transform=crs, norm=norm)
cbar = plt.colorbar(sc, orientation="horizontal", shrink=0.5, pad=0.05)
stitle = yaml_data['title_fig']+' \n '+'Mean |OMA| ='+str(field_mean)+', STDV |OMA| ='+str(field_std)
plt.title(stitle)
output_fn = yaml_data['output_prefix']+"_scatter.png"
plt.savefig(output_fn,dpi=300,bbox_inches='tight')
plt.savefig(output_fn,dpi=200,bbox_inches='tight')
plt.close('all')

def plot_histogram():
print("===== PLOT: HISTOGRAM =====")
field_mean = float("{:.2f}".format(np.mean(field)))
field_std = float("{:.2f}".format(np.std(field)))
print("Mean |OMA|=",field_mean)
print("STDV |OMA|=",field_std)
nbins = yaml_data['nbins']
xlimit = yaml_data['field_range']
plt.hist(field[:], bins=nbins, range=xlimit, density=True, color ="blue")
stitle = yaml_data['title_fig']+' \n '+'Mean(OMA) ='+str(field_mean)+', STDV(OMA) ='+str(field_std)
plt.title(stitle)
output_fn = yaml_data['output_prefix']+"_histogram.png"
plt.savefig(output_fn,dpi=300,bbox_inches='tight')
plt.savefig(output_fn,dpi=150,bbox_inches='tight')
plt.close('all')

if __name__ == '__main__':
Expand Down

0 comments on commit a56455d

Please sign in to comment.