Skip to content

Commit

Permalink
Removing white space in plot, setting clabels
Browse files Browse the repository at this point in the history
  • Loading branch information
doqhne committed Jun 10, 2022
1 parent f5e0d91 commit d17e961
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions Gallery/Contours/NCL_coneff_8.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
NCL_coneff_8.py
================
===============
This script illustrates the following concepts:
- Drawing pressure/height contours
- Selectively coloring between contour levels
Expand Down Expand Up @@ -51,11 +51,16 @@
# Calculate zonal mean
uzon = u_int.mean(dim='lon')

# interpolate nan values
uzon = uzon.interpolate_na(dim='lat',
method='nearest',
fill_value='extrapolate')

###############################################################################
# Plot:

# Generate figure (set its size (width, height) in inches)
plt.figure(figsize=(7, 8))
plt.figure(figsize=(9, 10))
ax1 = plt.gca()

# Format log axis
Expand Down Expand Up @@ -86,14 +91,16 @@
add_labels=False)

# Label the contours
# manual = [(-60, 39000), (-70, 51000), (50, 43000),
# (-40, 35000), (-10, 40000), (-29, 85000),
# (-35, 75000), (-55, 30000)]
manual = [(-70, 55000), (-80, 26000), (-72, 22500), (-62, 40000), (-58, 30000),
(-45, 69500), (-40, 34000), (-12, 39000), (-37, 75000), (40, 50000),
(-25, 42000), (18, 23000), (30, 40000), (45, 40000), (57, 41000),
(63, 39000), (55, 80000), (65, 85000)]
clabels = ax1.clabel(p,
levels=np.arange(0, 25, 8),
fontsize=10,
fontsize=12,
colors="black",
fmt="%.0f")
fmt="%.0f",
manual=manual)
# Set background color to white for contour labels
[
txt.set_bbox(dict(facecolor='white', edgecolor='none', pad=2))
Expand All @@ -114,15 +121,15 @@
gv.add_major_minor_ticks(ax1,
x_minor_per_major=3,
y_minor_per_major=0,
labelsize=14)
labelsize=15)

# Add second axis to plot heights (heights chosen arbitrarily)
gv.add_right_hand_axis(ax1,
label="Height (km)",
ylim=(0, 13),
yticks=np.array([4, 8]),
ticklabelsize=14,
axislabelsize=20)
ticklabelsize=15,
axislabelsize=21)

# Turn off tick marks on y-axis, set length and width parameters for x-axis
ax1.tick_params(axis='y', which='minor', left=False, right=False)
Expand Down

0 comments on commit d17e961

Please sign in to comment.