Skip to content

Commit

Permalink
Merge pull request #500 from jukent/pressure2height
Browse files Browse the repository at this point in the history
Right vertical axis height be calculated
  • Loading branch information
jukent committed Apr 10, 2023
2 parents 7221daf + 47a07c9 commit 8baa072
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
21 changes: 17 additions & 4 deletions Gallery/Contours/NCL_h_lat_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
import cmaps
import metpy.calc as mpcalc
from metpy.units import units

import scipy

import geocat.datafiles as gdf
import geocat.viz as gv
Expand Down Expand Up @@ -104,13 +108,22 @@
labelfontsize=16)

# Create second y-axis to show geo-potential height.
# Currently we're using arbitrary values for height as we haven't figured out
# how to make this work properly yet
axRHS = ax.twinx()

# Use geocat.viz.util convenience function to set axes tick values
gv.set_axes_limits_and_ticks(axRHS, ylim=(0, 32), yticks=np.arange(4, 32, 4))
# Select heights to display as tick labels
heights_nice = np.arange(0, 32, 4)
# Send "nice" height values back to pressure as tick locations
pressures_nice = mpcalc.height_to_pressure_std(heights_nice *
units('km')).magnitude

axRHS.set_yscale('log')
gv.set_axes_limits_and_ticks(axRHS,
ylim=ax.get_ylim(),
yticks=pressures_nice,
yticklabels=heights_nice)

axRHS.tick_params(labelsize=12) # manually set tick label size
axRHS.minorticks_off()

# Use geocat.viz.util convenience function to add titles and the pressure label
gv.set_titles_and_labels(axRHS, ylabel='Height (km)', labelfontsize=16)
Expand Down
21 changes: 16 additions & 5 deletions Gallery/Contours/NCL_h_lat_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import xarray as xr
from matplotlib import pyplot as plt
import numpy as np
import metpy.calc as mpcalc
from metpy.units import units

import geocat.datafiles as gdf
import geocat.viz as gv
Expand Down Expand Up @@ -189,13 +191,22 @@
ylabel='Pressure (mb)',
labelfontsize=24)

# Create second y-axis to show geo-potential height. Currently we're using
# arbitrary values for height as we haven't figured out how to make this work
# properly yet.
# Create second y-axis to show geo-potential height.
axRHS = ax.twinx()

# Use geocat.viz.util convenience function to set axes tick values
gv.set_axes_limits_and_ticks(axRHS, ylim=(0, 13), yticks=np.array([4, 8]))
# Select heights to display as tick labels
heights_nice = np.arange(0, 12, 4)
# Send "nice" height values back to pressure as tick locations
pressures_nice = mpcalc.height_to_pressure_std(heights_nice *
units('km')).magnitude

axRHS.set_yscale('log')
gv.set_axes_limits_and_ticks(axRHS,
ylim=ax.get_ylim(),
yticks=pressures_nice,
yticklabels=heights_nice)
axRHS.tick_params(labelsize=12) # manually set tick label size
axRHS.minorticks_off()

# manually set tick length, width and ticklabel size
axRHS.tick_params(labelsize=18, length=8, width=0.9)
Expand Down
20 changes: 15 additions & 5 deletions Gallery/Contours/NCL_h_long_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
import cmaps
import metpy.calc as mpcalc
from metpy.units import units

import geocat.datafiles as gdf
import geocat.viz as gv
Expand Down Expand Up @@ -107,14 +109,22 @@
ylabel=U.lev.long_name,
labelfontsize=18)

# Create second y-axis to show geo-potential height. Currently we're using
# arbitrary values for height as we haven't figured out how to make this work
# properly yet.
# Create second y-axis to show geo-potential height.
axRHS = ax.twinx()

# Use geocat.viz.util convenience function to set axes tick values
gv.set_axes_limits_and_ticks(axRHS, ylim=(0, 32), yticks=np.arange(4, 32, 4))
# Select heights to display as tick labels
heights_nice = np.arange(0, 32, 4)
# Send "nice" height values back to pressure as tick locations
pressures_nice = mpcalc.height_to_pressure_std(heights_nice *
units('km')).magnitude

axRHS.set_yscale('log')
gv.set_axes_limits_and_ticks(axRHS,
ylim=ax.get_ylim(),
yticks=pressures_nice,
yticklabels=heights_nice)
axRHS.tick_params(labelsize=12) # manually set tick label size
axRHS.minorticks_off()

# Use geocat.viz.util convenience function to add titles and the pressure label
axRHS.set_ylabel(ylabel='Height (km)', labelpad=10, fontsize=18)
Expand Down
21 changes: 16 additions & 5 deletions Gallery/Vectors/NCL_vector_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from matplotlib import pyplot as plt
from scipy.interpolate import interp2d
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
import metpy.calc as mpcalc
from metpy.units import units

import geocat.datafiles as gdf
import geocat.viz as gv
Expand Down Expand Up @@ -195,13 +197,22 @@
ylabel='Pressure (mb)',
labelfontsize=28)

# Create second y-axis to show geo-potential height. Currently we're using
# arbitrary values for height as we haven't figured out how to make this work
# properly yet.
# Create second y-axis to show geo-potential height.
axRHS = ax.twinx()

# Use geocat.viz.util convenience function to set axes tick values
gv.set_axes_limits_and_ticks(axRHS, ylim=(0, 13), yticks=np.array([4, 8]))
# Select heights to display as tick labels
heights_nice = np.arange(0, 12, 4)
# Send "nice" height values back to pressure as tick locations
pressures_nice = mpcalc.height_to_pressure_std(heights_nice *
units('km')).magnitude

axRHS.set_yscale('log')
gv.set_axes_limits_and_ticks(axRHS,
ylim=ax.get_ylim(),
yticks=pressures_nice,
yticklabels=heights_nice)
axRHS.tick_params(labelsize=12) # manually set tick label size
axRHS.minorticks_off()

# manually set tick length, width and ticklabel size
axRHS.tick_params(labelsize=16, length=8, width=0.9)
Expand Down

0 comments on commit 8baa072

Please sign in to comment.