Skip to content

Commit

Permalink
Add Stüve, Emagram plots
Browse files Browse the repository at this point in the history
Stüve and Emagram plots are enabled as child classes of SkewT parent class.
The child classes inherit plotting capabilities from SkewT (e.g. data, wind barbs, dry and saturated adiabats, and mixing ratio lines).
  • Loading branch information
cdholmes authored and dcamron committed Jan 9, 2025
1 parent 9451c3f commit e2a0d93
Showing 1 changed file with 101 additions and 3 deletions.
104 changes: 101 additions & 3 deletions src/metpy/plots/skewt.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2014,2015,2016,2017,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Make Skew-T Log-P based plots.
"""Make thermodynamic diagrams.
Contain tools for making Skew-T Log-P plots, including the base plotting class,
`SkewT`, as well as a class for making a `Hodograph`.
Contain tools for making thermodynamic diagrams, including the base plotting class,
`SkewT`, derived `Stuve` and `Emagram` classes, and a class for making a `Hodograph`.
"""

from contextlib import ExitStack
Expand Down Expand Up @@ -744,6 +744,104 @@ def shade_cin(self, pressure, t, t_parcel, dewpoint=None, **kwargs):
**kwargs)


@exporter.export
class Stuve(SkewT):
r"""Make Stüve plots of data.
Stüve plots are are a thermodynamic diagram with temperature on the x-axis and
pressure scaled by p^(R/cp)=p^0.286 on the y-axis. This class is derived from the
SkewT class and has the same capabilities for plotting data, wind barbs,
dry and saturated adiabats, and mixing ratio lines.
Attributes
----------
ax : `matplotlib.axes.Axes`
The underlying Axes instance, which can be used for calling additional
plot functions (e.g. `axvline`)
"""

def __init__(self, fig=None, subplot=None, rect=None, aspect='auto'):
r"""Create Stüve plots.
Parameters
----------
fig : matplotlib.figure.Figure, optional
Source figure to use for plotting. If none is given, a new
:class:`matplotlib.figure.Figure` instance will be created.
subplot : tuple[int, int, int] or `matplotlib.gridspec.SubplotSpec` instance, optional
Controls the size/position of the created subplot. This allows creating
the skewT as part of a collection of subplots. If subplot is a tuple, it
should conform to the specification used for
:meth:`matplotlib.figure.Figure.add_subplot`. The
:class:`matplotlib.gridspec.SubplotSpec`
can be created by using :class:`matplotlib.gridspec.GridSpec`.
rect : tuple[float, float, float, float], optional
Rectangle (left, bottom, width, height) in which to place the axes. This
allows the user to place the axes at an arbitrary point on the figure.
aspect : float, int, or Literal['auto'], optional
Aspect ratio (i.e. ratio of y-scale to x-scale) to maintain in the plot.
Defaults to ``'auto'`` which tells matplotlib to handle
the aspect ratio automatically.
"""
super().__init__(fig=fig, rotation=0, subplot=subplot, rect=rect, aspect=aspect)

# Forward (f) and inverse (g) functions for Stuve pressure coordinate scaling
def f(p):
return p**0.286

def g(p):
return p**(1 / 0.286)

# Set the yaxis as Stuve
self.ax.set_yscale('function', functions=(f, g))


@exporter.export
class Emagram(SkewT):
r"""Make Emagram plots of data.
Emagram plots are T log-P thermodynamic diagrams. They differ from SkewT
in that the T axis is not skewed. This class is derived from the SkewT class and
has the same capabilities for plotting data, wind barbs, dry and saturated
adiabats, and mixing ratio lines.
Attributes
----------
ax : `matplotlib.axes.Axes`
The underlying Axes instance, which can be used for calling additional
plot functions (e.g. `axvline`)
"""

def __init__(self, fig=None, subplot=None, rect=None, aspect='auto'):
r"""Create Emagram plots.
Parameters
----------
fig : matplotlib.figure.Figure, optional
Source figure to use for plotting. If none is given, a new
:class:`matplotlib.figure.Figure` instance will be created.
subplot : tuple[int, int, int] or `matplotlib.gridspec.SubplotSpec` instance, optional
Controls the size/position of the created subplot. This allows creating
the skewT as part of a collection of subplots. If subplot is a tuple, it
should conform to the specification used for
:meth:`matplotlib.figure.Figure.add_subplot`. The
:class:`matplotlib.gridspec.SubplotSpec`
can be created by using :class:`matplotlib.gridspec.GridSpec`.
rect : tuple[float, float, float, float], optional
Rectangle (left, bottom, width, height) in which to place the axes. This
allows the user to place the axes at an arbitrary point on the figure.
aspect : float, int, or Literal['auto'], optional
Aspect ratio (i.e. ratio of y-scale to x-scale) to maintain in the plot.
Defaults to ``'auto'`` which tells matplotlib to handle
the aspect ratio automatically.
"""
super().__init__(fig=fig, rotation=0, subplot=subplot, rect=rect, aspect=aspect)


@exporter.export
class Hodograph:
r"""Make a hodograph of wind data.
Expand Down

0 comments on commit e2a0d93

Please sign in to comment.