Skip to content

Commit

Permalink
Merge pull request #1162 from zbruick/skewt_lines
Browse files Browse the repository at this point in the history
Add handles to SkewT special lines
  • Loading branch information
dopplershift authored Sep 26, 2019
2 parents 811bfeb + 69c4267 commit f35d19e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 22 additions & 3 deletions metpy/plots/skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def __init__(self, fig=None, rotation=30, subplot=None, rect=None):
self.ax = fig.add_subplot(*subplot, projection='skewx', rotation=rotation)
self.ax.grid(True)

self.mixing_lines = None
self.dry_adiabats = None
self.moist_adiabats = None

def plot(self, p, t, *args, **kwargs):
r"""Plot data.
Expand Down Expand Up @@ -448,6 +452,10 @@ def plot_dry_adiabats(self, t0=None, p=None, **kwargs):
:class:`matplotlib.collections.LineCollection`
"""
# Remove old lines
if self.dry_adiabats:
self.dry_adiabats.remove()

# Determine set of starting temps if necessary
if t0 is None:
xmin, xmax = self.ax.get_xlim()
Expand All @@ -465,7 +473,8 @@ def plot_dry_adiabats(self, t0=None, p=None, **kwargs):
kwargs.setdefault('colors', 'r')
kwargs.setdefault('linestyles', 'dashed')
kwargs.setdefault('alpha', 0.5)
return self.ax.add_collection(LineCollection(linedata, **kwargs))
self.dry_adiabats = self.ax.add_collection(LineCollection(linedata, **kwargs))
return self.dry_adiabats

def plot_moist_adiabats(self, t0=None, p=None, **kwargs):
r"""Plot moist adiabats.
Expand Down Expand Up @@ -500,6 +509,10 @@ def plot_moist_adiabats(self, t0=None, p=None, **kwargs):
:class:`matplotlib.collections.LineCollection`
"""
# Remove old lines
if self.moist_adiabats:
self.moist_adiabats.remove()

# Determine set of starting temps if necessary
if t0 is None:
xmin, xmax = self.ax.get_xlim()
Expand All @@ -518,7 +531,8 @@ def plot_moist_adiabats(self, t0=None, p=None, **kwargs):
kwargs.setdefault('colors', 'b')
kwargs.setdefault('linestyles', 'dashed')
kwargs.setdefault('alpha', 0.5)
return self.ax.add_collection(LineCollection(linedata, **kwargs))
self.moist_adiabats = self.ax.add_collection(LineCollection(linedata, **kwargs))
return self.moist_adiabats

def plot_mixing_lines(self, w=None, p=None, **kwargs):
r"""Plot lines of constant mixing ratio.
Expand Down Expand Up @@ -549,6 +563,10 @@ def plot_mixing_lines(self, w=None, p=None, **kwargs):
:class:`matplotlib.collections.LineCollection`
"""
# Remove old lines
if self.mixing_lines:
self.mixing_lines.remove()

# Default mixing level values if necessary
if w is None:
w = np.array([0.0004, 0.001, 0.002, 0.004, 0.007, 0.01,
Expand All @@ -566,7 +584,8 @@ def plot_mixing_lines(self, w=None, p=None, **kwargs):
kwargs.setdefault('colors', 'g')
kwargs.setdefault('linestyles', 'dashed')
kwargs.setdefault('alpha', 0.8)
return self.ax.add_collection(LineCollection(linedata, **kwargs))
self.mixing_lines = self.ax.add_collection(LineCollection(linedata, **kwargs))
return self.mixing_lines

def shade_area(self, y, x1, x2=0, which='both', **kwargs):
r"""Shade area between two curves.
Expand Down
5 changes: 5 additions & 0 deletions metpy/plots/tests/test_skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def test_skewt_api():
skew.plot_moist_adiabats()
skew.plot_mixing_lines()

# Call again to hit removal statements
skew.plot_dry_adiabats()
skew.plot_moist_adiabats()
skew.plot_mixing_lines()

return fig


Expand Down

0 comments on commit f35d19e

Please sign in to comment.