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 functionality to hodograph #3109

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 32 additions & 9 deletions src/metpy/plots/skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from matplotlib.projections import register_projection
import matplotlib.spines as mspines
from matplotlib.ticker import MultipleLocator, NullFormatter, ScalarFormatter
from matplotlib.font_manager import FontManager
import matplotlib.transforms as transforms
import numpy as np

Expand Down Expand Up @@ -781,23 +782,28 @@ def __init__(self, ax=None, component_range=80):
# == sqrt(2) * max_range, which is the distance at the corner
self.max_range = 1.4142135 * component_range

def add_grid(self, increment=10., **kwargs):
r"""Add grid lines to hodograph.
def add_grid(self, increment=10., ring_labels=True, grid_ticks=False, **kwargs):
"""
Add grid lines to the hodograph plot.

Creates lines for the x- and y-axes, as well as circles denoting wind speed values.
This method creates lines for the x- and y-axes, as well as circles denoting wind speed values.

Parameters
----------
increment : int, optional
The value increment between rings
kwargs
Other kwargs to control appearance of lines
The value increment between rings denoting wind speed values.
ring_labels : bool, optional
Whether to include labels for each ring denoting wind speed values.
grid_ticks : bool, optional
Whether to include grid ticks along the axes.
**kwargs
Additional keyword arguments to control the appearance of the lines.

See Also
--------
:class:`matplotlib.patches.Circle`
:meth:`matplotlib.axes.Axes.axhline`
:meth:`matplotlib.axes.Axes.axvline`
matplotlib.patches.Circle
matplotlib.axes.Axes.axhline
matplotlib.axes.Axes.axvline

"""
# Some default arguments. Take those, and update with any
Expand All @@ -817,11 +823,28 @@ def add_grid(self, increment=10., **kwargs):
c = Circle((0, 0), radius=r, **circle_args)
self.ax.add_patch(c)
self.rings.append(c)

if ring_labels:
default_fontsize = FontManager().get_default_size()
max_fontsize = default_fontsize - 2
label_size = min(max_fontsize, default_fontsize - 2)
# Calculate label coordinates dynamically based on the circle radius
label_x = -r - 2
if self.max_range < 50:
label_y = - 5 # Adjust the factor as needed
else:
label_y = - 10
self.ax.annotate(f'{int(r)}', xy=(label_x, label_y), xycoords='data', va='center',
zorder=Line2D.zorder + 1, fontsize=label_size)

# Add lines for x=0 and y=0
self.yaxis = self.ax.axvline(0, **grid_args)
self.xaxis = self.ax.axhline(0, **grid_args)

if not grid_ticks:
self.ax.set_xticks([])
self.ax.set_yticks([])

@staticmethod
def _form_line_args(kwargs):
"""Simplify taking the default line style and extending with kwargs."""
Expand Down