Skip to content

Commit

Permalink
Update NCL_sat_3.py ticks and formatting (#571)
Browse files Browse the repository at this point in the history
* update NCL_sat_3.py to remove no longer needed helper code and adjust layering

* fix colorbar ticks on NCL_sat_3.py
  • Loading branch information
kafitzgerald committed Dec 8, 2023
1 parent eedec79 commit 2225e45
Showing 1 changed file with 13 additions and 70 deletions.
83 changes: 13 additions & 70 deletions Gallery/MapProjections/NCL_sat_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,6 @@

import geocat.viz as gv

###############################################################################
# Define a helper function for plotting lat/lon ticks on an orthographic plane


def plotOrthoTicks(coords, loc):

if loc == 'zero':
for lon, lat in coords:
ax.text(lon,
lat,
'{0}\N{DEGREE SIGN}'.format(lon),
va='bottom',
ha='center',
transform=ccrs.PlateCarree())
if loc == 'left':
for lon, lat in coords:
ax.text(lon,
lat,
'{0}\N{DEGREE SIGN} N '.format(lat),
va='center',
ha='right',
transform=ccrs.PlateCarree())

if loc == 'right':
for lon, lat in coords:
ax.text(lon,
lat,
'{0}\N{DEGREE SIGN} N '.format(lat),
va='center',
ha='left',
transform=ccrs.PlateCarree())

if loc == 'top':
for lon, lat in coords:
ax.text(lon,
lat,
'{0}\N{DEGREE SIGN} W '.format(-lon),
va='bottom',
ha='center',
transform=ccrs.PlateCarree())

if loc == 'bottom':
for lon, lat in coords:
ax.text(lon,
lat,
'{0}\N{DEGREE SIGN} W '.format(-lon),
va='top',
ha='center',
transform=ccrs.PlateCarree())


###############################################################################
# Read in data:

Expand All @@ -102,13 +51,13 @@ def plotOrthoTicks(coords, loc):

# Add natural feature to map
ax.coastlines(resolution='110m')
ax.add_feature(cfeature.LAND, facecolor='lightgray', zorder=3)
ax.add_feature(cfeature.COASTLINE, linewidth=0.2, zorder=3)
ax.add_feature(cfeature.LAND, facecolor='lightgray', zorder=1.25)
ax.add_feature(cfeature.COASTLINE, linewidth=0.2, zorder=1.5)
ax.add_feature(cfeature.LAKES,
edgecolor='black',
linewidth=0.2,
facecolor='white',
zorder=4)
zorder=1.5)

# plot filled contour data
heatmap = t.plot.contourf(ax=ax,
Expand All @@ -118,7 +67,7 @@ def plotOrthoTicks(coords, loc):
vmax=28.5,
cmap='RdGy',
add_colorbar=False,
zorder=1)
zorder=0.5)

# Add color bar
cbar_ticks = np.arange(-1.5, 31.5, 3)
Expand All @@ -133,6 +82,9 @@ def plotOrthoTicks(coords, loc):

cbar.ax.tick_params(labelsize=10)

# Remove minor ticks that don't work well with other formatting
cbar.ax.minorticks_off()

# Get rid of black outline on colorbar
cbar.outline.set_visible(False)

Expand All @@ -156,21 +108,12 @@ def plotOrthoTicks(coords, loc):
ylabel="")

# Plot gridlines
gl = ax.gridlines(color='black', linewidth=0.2, zorder=2)

# Set frequency of gridlines in the x and y directions
gl.xlocator = mticker.FixedLocator(np.arange(-180, 180, 15))
gl.ylocator = mticker.FixedLocator(np.arange(-90, 90, 15))

# Manually plot tick marks.
# NCL has automatic tick mark placement on orthographic projections,
# Python's cartopy module does not have this functionality yet.
plotOrthoTicks([(0, 81.7)], 'zero')
plotOrthoTicks([(-80, 30), (-76, 20), (-88, 40), (-107, 50)], 'left')
plotOrthoTicks([(-9, 30), (-6, 40), (1, 50), (13, 60)], 'right')
plotOrthoTicks([(-120, 60), (-60, 82.5)], 'top')
plotOrthoTicks([(-75, 16.0), (-60, 25.0), (-45, 29.0), (-30, 29.5),
(-15, 26.5)], 'bottom')
gl = ax.gridlines(color='black',
linewidth=0.2,
zorder=1,
xlocs=np.arange(-180, 180, 15),
ylocs=np.arange(-90, 90, 15),
draw_labels=True)

plt.tight_layout()
plt.show()

0 comments on commit 2225e45

Please sign in to comment.