Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_skewt_shade_area_kwargs(test_profile):
"""Test shading areas on a SkewT plot with kwargs."""
p, t, tp = test_profile
with matplotlib.rc_context({'axes.autolimit_mode': 'data'}):
fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, aspect='auto')
skew.plot(p, t, 'r')
skew.plot(p, tp, 'k')
skew.shade_area(p, t, tp, facecolor='m')
skew.ax.set_xlim(-50, 50)
skew.ax.set_ylim(1000, 100)
return fig
def test_skewt_wide_aspect_ratio(test_profile):
"""Test plotting a skewT with a wide aspect ratio."""
p, t, tp = test_profile
fig = plt.figure(figsize=(12.5, 3))
skew = SkewT(fig, aspect='auto')
skew.plot(p, t, 'r')
skew.plot(p, tp, 'k')
skew.ax.set_xlim(-30, 50)
skew.ax.set_ylim(1050, 700)
return fig
def test_skewt_shade_area_invalid(test_profile):
"""Test shading areas on a SkewT plot."""
p, t, tp = test_profile
fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, aspect='auto')
skew.plot(p, t, 'r')
skew.plot(p, tp, 'k')
with pytest.raises(ValueError):
skew.shade_area(p, t, tp, which='positve')
def test_skewt_default_aspect_empty():
"""Test SkewT with default aspect and no plots, only special lines."""
# With this rotation and the default aspect, this matches exactly the NWS SkewT PDF
fig = plt.figure(figsize=(12, 9))
skew = SkewT(fig, rotation=43)
skew.plot_dry_adiabats()
skew.plot_moist_adiabats()
skew.plot_mixing_lines()
return fig
def test_skewt_barb_color():
"""Test plotting colored wind barbs on the Skew-T."""
fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, aspect='auto')
p = np.linspace(1000, 100, 10)
u = np.linspace(-10, 10, 10)
skew.plot_barbs(p, u, u, c=u)
return fig
def test_skewt_subplot():
"""Test using SkewT on a sub-plot."""
fig = plt.figure(figsize=(9, 9))
SkewT(fig, subplot=(2, 2, 1), aspect='auto')
return fig
def test_skewt_units():
"""Test that plotting with SkewT works with units properly."""
fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, aspect='auto')
skew.ax.axvline(np.array([273]) * units.kelvin, color='purple')
skew.ax.axhline(np.array([50000]) * units.Pa, color='red')
skew.ax.axvline(np.array([-20]) * units.degC, color='darkred')
skew.ax.axvline(-10, color='orange')
return fig
#
# 1. Create a ``Figure`` object and set the size of the figure.
#
# 2. Create a ``SkewT`` object
#
# 3. Plot the pressure and temperature (note that the pressure,
# the independent variable, is first even though it is plotted on the y-axis).
#
# 4. Plot the pressure and dewpoint temperature.
#
# 5. Plot the wind barbs at the appropriate pressure using the u and v wind
# components.
# Create a new figure. The dimensions here give a good aspect ratio
fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig)
# Plot the data using normal plotting functions, in this case using
# log scaling in Y, as dictated by the typical meteorological plot
skew.plot(p, T, 'r', linewidth=2)
skew.plot(p, Td, 'g', linewidth=2)
skew.plot_barbs(p, u, v)
# Show the plot
plt.show()
##########################################################################
# Advanced Skew-T Plotting
# ------------------------
#
# Fiducial lines indicating dry adiabats, moist adiabats, and mixing ratio are
# useful when performing further analysis on the Skew-T diagram. Often the
skew.plot_barbs(p, u, v)
# Show the plot
plt.show()
##########################################################################
# Advanced Skew-T Plotting
# ------------------------
#
# Fiducial lines indicating dry adiabats, moist adiabats, and mixing ratio are
# useful when performing further analysis on the Skew-T diagram. Often the
# 0C isotherm is emphasized and areas of CAPE and CIN are shaded.
# Create a new figure. The dimensions here give a good aspect ratio
fig = plt.figure(figsize=(9, 9))
skew = SkewT(fig, rotation=30)
# Plot the data using normal plotting functions, in this case using
# log scaling in Y, as dictated by the typical meteorological plot
skew.plot(p, T, 'r')
skew.plot(p, Td, 'g')
skew.plot_barbs(p, u, v)
skew.ax.set_ylim(1000, 100)
skew.ax.set_xlim(-40, 60)
# Plot LCL temperature as black dot
skew.plot(lcl_pressure, lcl_temperature, 'ko', markerfacecolor='black')
# Plot the parcel profile as a black line
skew.plot(p, parcel_prof, 'k', linewidth=2)
# Shade areas of CAPE and CIN
p = df['pressure'].values * units.hPa
T = df['temperature'].values * units.degC
Td = df['dewpoint'].values * units.degC
wind_speed = df['speed'].values * units.knots
wind_dir = df['direction'].values * units.degrees
u, v = mpcalc.wind_components(wind_speed, wind_dir)
###########################################
# Create a new figure. The dimensions here give a good aspect ratio
fig = plt.figure(figsize=(9, 9))
add_metpy_logo(fig, 630, 80, size='large')
# Grid for plots
gs = gridspec.GridSpec(3, 3)
skew = SkewT(fig, rotation=45, subplot=gs[:, :2])
# Plot the data using normal plotting functions, in this case using
# log scaling in Y, as dictated by the typical meteorological plot
skew.plot(p, T, 'r')
skew.plot(p, Td, 'g')
skew.plot_barbs(p, u, v)
skew.ax.set_ylim(1000, 100)
# Add the relevant special lines
skew.plot_dry_adiabats()
skew.plot_moist_adiabats()
skew.plot_mixing_lines()
# Good bounds for aspect ratio
skew.ax.set_xlim(-30, 40)