Skip to content

Commit

Permalink
Adjust contour levels and colorbar ticks to adapt to updates in Matpl…
Browse files Browse the repository at this point in the history
…otlib 3.6+ (#575)

* Fix minor ticks on NCL_animate_1.py colorbar and update a few comments

* adjust NCL_vector_1.py contour levels

* adjust NCL_mask_5.py contour levels

* adjust CB_Rain.py contour levels

* adjust CB_Height.py contour levels

* adjust CB_Temperature.py contour levels

* formatting
  • Loading branch information
kafitzgerald committed Dec 12, 2023
1 parent db2ac6e commit 1710a65
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
66 changes: 35 additions & 31 deletions Gallery/Animations/NCL_animate_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,51 +38,55 @@
# Create animation:

fig = plt.figure(figsize=(10, 8))

# Generate axes using Cartopy and draw coastlines
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=150))
ax.coastlines(linewidths=0.5)
ax.set_extent([-180, 180, -90, 90], ccrs.PlateCarree())

# Use geocat.viz.util convenience function to set axes limits & tick values
# Use geocat-viz convenience function to set axes limits & tick values
gv.set_axes_limits_and_ticks(ax,
xlim=(-180, 180),
ylim=(-90, 90),
xticks=np.linspace(-180, 180, 13),
yticks=np.linspace(-90, 90, 7))

# Use geocat.viz.util convenience function to add minor and major tick lines
# Use geocat-viz convenience function to add minor and major tick lines
gv.add_major_minor_ticks(ax, labelsize=10)

# Use geocat.viz.util convenience function to make latitude, longitude tick labels
# Use geocat-viz convenience function to make latitude, longitude tick labels
gv.add_lat_lon_ticklabels(ax)

# create initial plot that establishes a colorbar
tas[0, :, :].plot.contourf(ax=ax,
transform=ccrs.PlateCarree(),
vmin=195,
vmax=328,
levels=53,
cmap="inferno",
cbar_kwargs={
"extendrect": True,
"orientation": "horizontal",
"ticks": np.arange(195, 332, 9),
"label": "",
"shrink": 0.90
})


# animate function for matplotlib FuncAnimation
# Create initial plot
cplot = tas[0, :, :].plot.contourf(ax=ax,
transform=ccrs.PlateCarree(),
vmin=195,
vmax=328,
levels=53,
cmap="inferno",
add_colorbar=False)

# Create a colorbar
cbar = fig.colorbar(cplot,
extendrect=True,
orientation="horizontal",
ticks=np.arange(195, 332, 9),
label="",
shrink=0.90)

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


# Animate function for matplotlib FuncAnimation
def animate(i):
tas[i, :, :].plot.contourf(
ax=ax,
transform=ccrs.PlateCarree(),
vmin=195,
vmax=328,
levels=53,
cmap="inferno",
add_colorbar=False,
)
tas[i, :, :].plot.contourf(ax=ax,
transform=ccrs.PlateCarree(),
vmin=195,
vmax=328,
levels=53,
cmap="inferno",
add_colorbar=False)

gv.set_titles_and_labels(
ax,
Expand All @@ -92,8 +96,8 @@ def animate(i):
ylabel="")


# runs the animation initiated with the frame from init and progressed with the animate function
# Run the animation initiated with the frame from init and progressed with the animate function
anim = animation.FuncAnimation(fig, animate, frames=30, interval=200)

# Uncomment this line to save the created animation
# Uncomment this line to save the animation
#anim.save('animate_1.gif', writer='pillow', fps=5)
2 changes: 1 addition & 1 deletion Gallery/Colors/CB_Height.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def Plot(color, row, col, pos, title):
# Contourf-plot data
hgt = t.plot.contourf(ax=ax1,
transform=projection,
levels=40,
levels=31,
vmin=100,
vmax=1600,
cmap=newcmp,
Expand Down
2 changes: 1 addition & 1 deletion Gallery/Colors/CB_Rain.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def Plot(color, row, col, pos, title):
# Contourf-plot data
pre = t.plot.contourf(ax=ax1,
transform=projection,
levels=14,
levels=13,
vmin=0,
vmax=240,
cmap=newcmp,
Expand Down
2 changes: 1 addition & 1 deletion Gallery/Colors/CB_Temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def Plot(color, row, col, pos, title):
# Contourf-plot data
temp = t.plot.contourf(ax=ax1,
transform=projection,
levels=40,
levels=33,
vmin=0,
vmax=32,
cmap=newcmp,
Expand Down
4 changes: 2 additions & 2 deletions Gallery/Masking/NCL_mask_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
transform=ccrs.PlateCarree(),
vmin=235,
vmax=315,
levels=18,
levels=17,
cmap='magma',
add_colorbar=False)

Expand All @@ -103,7 +103,7 @@
extendrect=True,
extendfrac='auto',
use_gridspec=False,
ticks=np.arange(240, 315, 5))
ticks=np.arange(235, 315, 5))

cbar.ax.tick_params(labelsize=10)

Expand Down
4 changes: 2 additions & 2 deletions Gallery/Vectors/NCL_vector_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
sst_plot = sst.plot.contourf(
ax=ax,
transform=proj,
levels=50,
levels=51,
vmin=24,
vmax=28.8,
vmax=29,
cmap="magma",
add_colorbar=False,
)
Expand Down

0 comments on commit 1710a65

Please sign in to comment.