Closed xenct closed 2 weeks ago
Could this include subplots that have different colour bars (i.e., historical, projection, projection minus historical)? There are a few ways this could be done:
A colourbar could be added to each subplot in plot_acs_hazard_3pp if any of the input are lists (ticks, colormaps, cbar_label, etc).
Make calling plot_titles optional so that the border and outer text (issue date, etc) can be added around all subplots. This way, plot_acs_hazard
can be called three times with different inputs for each subplot. The subplots can be combined into one figure (before adding the frame) by:
a) Adding fig and ax as optional inputs to plot_acs_hazard
:
fig, axes = plt.subplots(
1, 3, figsize=(12, 4), subplot_kw=dict(projection=ccrs.PlateCarree())
)
for i in range(3):
fig, axes[i] = plot_acs_hazard(fig, axes[i], **kwargs)
fig, axes = plot_titles(fig, axes, **kwargs)
plt.savefig()
b) Saving each subplot as a temporary file and then combining them into one figure using mpl.image.imread:
outfile = "output.png"
files = ["output1.png", "output2.png", "output3.png"]
fig, axes = plt.subplots(1, 3, figsize=[12, 4], layout="compressed")
for i, ax in enumerate(axes.flatten()):
ax.axis("off")
img = matplotlib.image.imread(files[i])
ax.imshow(img)
ax.axis(False)
ax.tick_params(
axis="both",
which="both",
left=False,
right=False,
top=False,
bottom=False,
)
ax.xaxis.set_major_formatter(plt.NullFormatter())
ax.yaxis.set_major_formatter(plt.NullFormatter())
fig, axes = plot_titles(fig, axes, **kwargs)
plt.savefig(outfile, bbox_inches="tight", facecolor="white", dpi=300)
Further adaptations can be made to have more flexible multipanel plotting, but for the purpose the our NCRA request, below is an example of the new code. Further requests may include a baseline plot (GWL12) with three anomaly maps for example. Plot a three-panel plot
%%time
from plotting_maps.acs_plotting_maps import plot_acs_hazard_3pp
var = "HWAtx"
ds_gwl12 =xr.open_dataset("/g/data/ia39/ncra/heat/data/HWAtx/bias-corrected/ensemble/GWL-average/HWAtx_AGCD-05i_MME50_ssp370_v1-r1-ACS-QME-AGCD-1960-2022_GWL12.nc")
ds_gwl15 = xr.open_dataset("/g/data/ia39/ncra/heat/data/HWAtx/bias-corrected/ensemble/GWL-average/HWAtx_AGCD-05i_MME50_ssp370_v1-r1-ACS-QME-AGCD-1960-2022_GWL15.nc")
ds_gwl20 = xr.open_dataset("/g/data/ia39/ncra/heat/data/HWAtx/bias-corrected/ensemble/GWL-average/HWAtx_AGCD-05i_MME50_ssp370_v1-r1-ACS-QME-AGCD-1960-2022_GWL20.nc")
ds_gwl30 = xr.open_dataset("/g/data/ia39/ncra/heat/data/HWAtx/bias-corrected/ensemble/GWL-average/HWAtx_AGCD-05i_MME50_ssp370_v1-r1-ACS-QME-AGCD-1960-2022_GWL30.nc")
plot_acs_hazard_3pp(ds_gwl15 = ds_gwl15[var],
ds_gwl20 = ds_gwl20[var],
ds_gwl30 = ds_gwl30[var],
regions = regions_dict['ncra_regions'],
cbar_label=f"Temperature [degC]",
title=f"Maximum Temperature of Hottest Heatwave for future warming scenarios",
date_range = "Insert subtitle - should include the date range of the data \nand then the dataset below that",
# baseline = "GWL1.2",
dataset_name= "MME50_ssp370",
issued_date=None,
watermark="EXPERIMENTAL IMAGE ONLY",
watermark_color="k",
cmap = cmap_dict["tasmax"],
ticks = np.arange(18,53,2),)
Make three panel plots for climate hazard data. For example, to display GWL15, GWL2, GWL3 anomalies from GWL12 in a single figure.