Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method for plotting a range on a SkewT #2444

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/metpy/plots/skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,76 @@
return self.shade_area(pressure[idx], t_parcel[idx], t[idx], which='negative',
**kwargs)

def plot_vertical_range(self, y0, y1, x, *, width=0.04, align='mid', **kwargs):
"""Plot a vertical range indicator.

Draws a vertical staff, capped at either end by a horizontal line, used to denote
vertical regions of interest on the plot. The vertical extent of the range is
given by ``y0`` and ``y1`` and is centered at ``x``.

Parameters
----------
y0 : float or int
Starting point of the staff in data coordinates
y1 : float or int
Ending point of the staff in data coordinates
x : float
Horizontal location given in normalized axes coordinates, where 0 and 1 represent
the left and right edges, respectively.
width : float
Width of the caps, given in normalized axes coordinates where 1.0 is the full
width of the axes. Optional and defaults to 0.04.
align : {'left', 'mid', 'right'}
Where in the cap the staff should be aligned, optional. Defaults to 'mid'.
kwargs
Other keyword arguments, such as ``colors`` or ``linewidths``, to pass to
:class:`matplotlib.collections.LineCollection` to control the appearance.

Returns
-------
:class:`matplotlib.collections.LineCollection`

See Also
--------
:class:`matplotlib.collections.LineCollection`

Notes
-----
The indicator is drawn using a single :class:`~matplotlib.collections.LineCollection`
instance, in the order of vertical staff, cap at y0, cap at y1, forcing the caps
to draw on top the staff. This is important when providing multiple colors.

If the ``colors`` argument is not passed in, the default color is ``'black'``.

"""
# Override matplotlib's default color (tab:blue) since that doesn't work well
# for this on our default colors.
if 'colors' not in kwargs:
kwargs['colors'] = 'black'

Check warning on line 785 in src/metpy/plots/skewt.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/plots/skewt.py#L784-L785

Added lines #L784 - L785 were not covered by tests

# Configure how the top bars are aligned to the middle staff
if align == 'left':
left = x
right = x + width
elif align == 'mid':
left = x - width / 2
right = x + width / 2
elif align == 'right':
left = x - width
right = x

Check warning on line 796 in src/metpy/plots/skewt.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/plots/skewt.py#L788-L796

Added lines #L788 - L796 were not covered by tests
else:
raise ValueError('align should be one of "left", "right", or "mid".')

Check warning on line 798 in src/metpy/plots/skewt.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/plots/skewt.py#L798

Added line #L798 was not covered by tests

# Need to convert units before giving to LineCollection
y0 = self.ax.convert_yunits(y0)
y1 = self.ax.convert_yunits(y1)

Check warning on line 802 in src/metpy/plots/skewt.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/plots/skewt.py#L801-L802

Added lines #L801 - L802 were not covered by tests

# Create the collection where the x is given in axes coords, y in data coords.
lc = LineCollection([[(x, y0), (x, y1)], # staff

Check warning on line 805 in src/metpy/plots/skewt.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/plots/skewt.py#L805

Added line #L805 was not covered by tests
[(left, y0), (right, y0)], [(left, y1), (right, y1)]], # caps
transform=self.ax.get_yaxis_transform(), **kwargs)
return self.ax.add_collection(lc)

Check warning on line 808 in src/metpy/plots/skewt.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/plots/skewt.py#L808

Added line #L808 was not covered by tests


@exporter.export
class Hodograph:
Expand Down