Skip to content

Commit

Permalink
clean up and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 committed Nov 30, 2023
1 parent b36a5f0 commit 9bdba9d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pcmdi_metrics/variability_mode/lib/plot_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def plot_map_cartopy(

debug_print("Central longitude setup starts", debug)
debug_print("proj: " + proj, debug)

# map types example:
# https://github.com/SciTools/cartopy-tutorial/blob/master/tutorial/projections_crs_and_terms.ipynb

Expand Down Expand Up @@ -267,13 +267,16 @@ def plot_map_cartopy(
# every 1 degree so that the result is smooth:
# https://stackoverflow.com/questions/43463643/cartopy-albersequalarea-limit-region-using-lon-and-lat

# vertices = [
# (lon - 180, lat_min) for lon in range(int(lon_min), int(lon_max + 1), 1)
# ] + [(lon - 180, lat_max) for lon in range(int(lon_max), int(lon_min - 1), -1)]
vertices = [
(lon - 180, lat_min) for lon in range(int(lon_min), int(lon_max + 1), 1)
] + [(lon - 180, lat_max) for lon in range(int(lon_max), int(lon_min - 1), -1)]
(lon - 180, lat_min) for lon in range(int(lon_min), int(lon_max), 1)
] + [(lon - 180, lat_max) for lon in range(int(lon_max), int(lon_min), -1)]
boundary = mpath.Path(vertices)
ax.set_boundary(
boundary, transform=ccrs.PlateCarree(central_longitude=central_longitude)
)
boundary, transform=ccrs.PlateCarree(central_longitude=180)
) # Here, 180 should be hardcoded, otherwise AMO map will be at out of figure box

ax.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree())

Expand All @@ -299,7 +302,7 @@ def plot_map_cartopy(
debug_print("projection completed", debug)

# Plot contours from the data
im = ax.contourf(
contourf_plot = ax.contourf(
lon,
lat,
data_array,
Expand All @@ -326,11 +329,11 @@ def plot_map_cartopy(
# Add title
ax.set_title(title, pad=15, fontsize=15)

# Add colorbar
# Add a colorbar
posn = ax.get_position()
cbar_ax = fig.add_axes([0, 0, 0.1, 0.1])
cbar_ax.set_position([posn.x0 + posn.width + 0.01, posn.y0, 0.01, posn.height])
cbar = plt.colorbar(im, cax=cbar_ax)
cbar_ax.set_position([posn.x0 + posn.width + 0.03, posn.y0, 0.01, posn.height])
cbar = plt.colorbar(contourf_plot, cax=cbar_ax)
cbar.ax.tick_params(labelsize=10)

# Done, save figure
Expand Down

0 comments on commit 9bdba9d

Please sign in to comment.