Skip to content

Commit

Permalink
Merge pull request #16 from AusClimateService/plotting_scatter_3
Browse files Browse the repository at this point in the history
Plotting scatter 3
  • Loading branch information
xenct authored Jul 26, 2024
2 parents a97761e + 09a2580 commit 26ec4de
Show file tree
Hide file tree
Showing 2 changed files with 1,303 additions and 2 deletions.
45 changes: 43 additions & 2 deletions acs_plotting_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def plot_acs_hazard(
name="aus_states_territories",
regions=None,
data=None,
station_df=None,
stippling=None,
mask_not_australia=True,
facecolor=None,
Expand Down Expand Up @@ -270,6 +271,12 @@ def plot_acs_hazard(
average, sum, anomaly, metric or index you wish to visualise.
This function is resolution agnostic.
station_df: pd.DataFrame, optional
a pandas.DataFrame with columns ["lon", "lat", variable].
If station_df is given, then variable values are represented as dots on
the map accoring to at the lat lon coordinates and colored according to
cmap colors and ticks.
stippling: xr.DataArray
a True/False to define regions of stippling hatching.
Intended to show model agreement, eg for direction of change.
Expand Down Expand Up @@ -405,14 +412,16 @@ def plot_acs_hazard(
The map is saved as a png in a "figures" file in your working directory.
This function returns fig and ax.
"""
cbar = None

middle_ticks = []
if regions is None:
try:
regions = regions_dict[name]
except:
print(f"Could not read regions_dict[{name}]")

# Set default crs for Australia maps and selction maps
# Set default crs for Australia maps and selection maps
if crs is None:
if select_area is None:
# Default for Australian map
Expand Down Expand Up @@ -442,6 +451,35 @@ def plot_acs_hazard(
if infile is not None:
data = xr.open_dataset(infile)

# for station data
if station_df is not None:
# assuming columns are named "lon", "lat", variable,
gdf = gpd.GeoDataFrame(
station_df, geometry=gpd.points_from_xy(station_df.lon, station_df.lat), crs=ccrs.PlateCarree()
)
var = gdf.columns[[2]][0]
norm = BoundaryNorm(ticks, cmap.N, extend=cbar_extend)
cont = ax.scatter(x=station_df.lon,
y=station_df.lat,
s=100,
c=station_df[var],
edgecolors="k",
alpha = 0.8,
zorder=6,
transform=ccrs.PlateCarree(),
cmap= cmap,
norm = norm)

cbar = plt.colorbar(
cont,
ax=ax,
extend=cbar_extend,
cax=ax.inset_axes([0.8, 0.2, 0.03, 0.6]),
ticks=ticks,
norm=norm,
)
facecolor = "lightgrey"

if data is not None:
data = data.squeeze()

Expand Down Expand Up @@ -518,7 +556,6 @@ def plot_acs_hazard(
elif len(middle_ticks) == len(tick_labels):
cbar.ax.set_yticks(middle_ticks, tick_labels)

cbar.ax.set_title(cbar_label, zorder=8, y=1.1, loc="center")
if contour and tick_labels is None:
cont = plt.contour(
data.lon,
Expand Down Expand Up @@ -623,6 +660,10 @@ def plot_acs_hazard(
zorder=10,
)

# Label colorbar
if cbar is not None:
cbar.ax.set_title(cbar_label, zorder=8, y=1.1, loc="center")

if baseline is not None:
# print base period inside bottom left corner
ax.text(
Expand Down
Loading

0 comments on commit 26ec4de

Please sign in to comment.