Skip to content

Profile Plots

ProfilePlot

Bases: BasePlot

Profile or cross-section plot.

Source code in src/monet_plots/plots/profile.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class ProfilePlot(BasePlot):
    """Profile or cross-section plot."""

    def __init__(
        self,
        *,
        x: np.ndarray,
        y: np.ndarray,
        z: np.ndarray | None = None,
        alt_adjust: float | None = None,
        **kwargs: t.Any,
    ) -> None:
        """
        Parameters
        ----------
        x
            X-axis data.
        y
            Y-axis data.
        z
            Optional Z-axis data for contour plots.
        alt_adjust
            Value to subtract from the y-axis data for altitude adjustment.
        **kwargs
            Keyword arguments passed to the parent class.
        """
        super().__init__(**kwargs)
        self.x = x
        if alt_adjust is not None:
            self.y = y - alt_adjust
        else:
            self.y = y
        self.z = z

    def plot(self, **kwargs: t.Any) -> None:
        """
        Parameters
        ----------
        **kwargs
            Keyword arguments passed to `matplotlib.pyplot.plot` or
            `matplotlib.pyplot.contourf`.
        """
        if self.ax is None:
            if self.fig is None:
                self.fig = plt.figure()
            self.ax = self.fig.add_subplot()

        if self.z is not None:
            self.ax.contourf(self.x, self.y, self.z, **kwargs)
        else:
            self.ax.plot(self.x, self.y, **kwargs)

__init__(*, x, y, z=None, alt_adjust=None, **kwargs)

Parameters

x X-axis data. y Y-axis data. z Optional Z-axis data for contour plots. alt_adjust Value to subtract from the y-axis data for altitude adjustment. **kwargs Keyword arguments passed to the parent class.

Source code in src/monet_plots/plots/profile.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(
    self,
    *,
    x: np.ndarray,
    y: np.ndarray,
    z: np.ndarray | None = None,
    alt_adjust: float | None = None,
    **kwargs: t.Any,
) -> None:
    """
    Parameters
    ----------
    x
        X-axis data.
    y
        Y-axis data.
    z
        Optional Z-axis data for contour plots.
    alt_adjust
        Value to subtract from the y-axis data for altitude adjustment.
    **kwargs
        Keyword arguments passed to the parent class.
    """
    super().__init__(**kwargs)
    self.x = x
    if alt_adjust is not None:
        self.y = y - alt_adjust
    else:
        self.y = y
    self.z = z

plot(**kwargs)

Parameters

**kwargs Keyword arguments passed to matplotlib.pyplot.plot or matplotlib.pyplot.contourf.

Source code in src/monet_plots/plots/profile.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def plot(self, **kwargs: t.Any) -> None:
    """
    Parameters
    ----------
    **kwargs
        Keyword arguments passed to `matplotlib.pyplot.plot` or
        `matplotlib.pyplot.contourf`.
    """
    if self.ax is None:
        if self.fig is None:
            self.fig = plt.figure()
        self.ax = self.fig.add_subplot()

    if self.z is not None:
        self.ax.contourf(self.x, self.y, self.z, **kwargs)
    else:
        self.ax.plot(self.x, self.y, **kwargs)

VerticalSlice

Bases: ProfilePlot

Vertical cross-section plot.

Source code in src/monet_plots/plots/profile.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class VerticalSlice(ProfilePlot):
    """Vertical cross-section plot."""

    def __init__(self, *args, **kwargs):
        """
        Initialize the vertical slice plot.
        """
        super().__init__(*args, **kwargs)

    def plot(self, **kwargs: t.Any) -> None:
        """
        Parameters
        ----------
        **kwargs
            Keyword arguments passed to `matplotlib.pyplot.contourf`.
        """
        if self.ax is None:
            if self.fig is None:
                self.fig = plt.figure()
            self.ax = self.fig.add_subplot()

        self.ax.contourf(self.x, self.y, self.z, **kwargs)

__init__(*args, **kwargs)

Initialize the vertical slice plot.

Source code in src/monet_plots/plots/profile.py
68
69
70
71
72
def __init__(self, *args, **kwargs):
    """
    Initialize the vertical slice plot.
    """
    super().__init__(*args, **kwargs)

plot(**kwargs)

Parameters

**kwargs Keyword arguments passed to matplotlib.pyplot.contourf.

Source code in src/monet_plots/plots/profile.py
74
75
76
77
78
79
80
81
82
83
84
85
86
def plot(self, **kwargs: t.Any) -> None:
    """
    Parameters
    ----------
    **kwargs
        Keyword arguments passed to `matplotlib.pyplot.contourf`.
    """
    if self.ax is None:
        if self.fig is None:
            self.fig = plt.figure()
        self.ax = self.fig.add_subplot()

    self.ax.contourf(self.x, self.y, self.z, **kwargs)

Example

import numpy as np
from monet_plots.plots import VerticalSlice

# Create sample data
x = np.linspace(0, 10, 100)
y = np.linspace(0, 10, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)

# Create the plot
plot = VerticalSlice(x=X, y=Y, z=Z)
plot.plot()

StickPlot

Bases: BasePlot

Vertical stick plot.

Source code in src/monet_plots/plots/profile.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class StickPlot(BasePlot):
    """Vertical stick plot."""

    def __init__(self, u, v, y, *args, **kwargs):
        """
        Initialize the stick plot.
        Args:
            u (np.ndarray, pd.Series, xr.DataArray): U-component of the vector.
            v (np.ndarray, pd.Series, xr.DataArray): V-component of the vector.
            y (np.ndarray, pd.Series, xr.DataArray): Vertical coordinate.
            **kwargs: Additional keyword arguments passed to BasePlot.
        """
        super().__init__(*args, **kwargs)
        self.u = u
        self.v = v
        self.y = y
        self.x = np.zeros_like(self.y)

    def plot(self, **kwargs: t.Any) -> None:
        """
        Parameters
        ----------
        **kwargs
            Keyword arguments passed to `matplotlib.pyplot.quiver`.
        """
        if self.ax is None:
            if self.fig is None:
                self.fig = plt.figure()
            self.ax = self.fig.add_subplot()

        return self.ax.quiver(self.x, self.y, self.u, self.v, **kwargs)

__init__(u, v, y, *args, **kwargs)

Initialize the stick plot. Args: u (np.ndarray, pd.Series, xr.DataArray): U-component of the vector. v (np.ndarray, pd.Series, xr.DataArray): V-component of the vector. y (np.ndarray, pd.Series, xr.DataArray): Vertical coordinate. **kwargs: Additional keyword arguments passed to BasePlot.

Source code in src/monet_plots/plots/profile.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def __init__(self, u, v, y, *args, **kwargs):
    """
    Initialize the stick plot.
    Args:
        u (np.ndarray, pd.Series, xr.DataArray): U-component of the vector.
        v (np.ndarray, pd.Series, xr.DataArray): V-component of the vector.
        y (np.ndarray, pd.Series, xr.DataArray): Vertical coordinate.
        **kwargs: Additional keyword arguments passed to BasePlot.
    """
    super().__init__(*args, **kwargs)
    self.u = u
    self.v = v
    self.y = y
    self.x = np.zeros_like(self.y)

plot(**kwargs)

Parameters

**kwargs Keyword arguments passed to matplotlib.pyplot.quiver.

Source code in src/monet_plots/plots/profile.py
107
108
109
110
111
112
113
114
115
116
117
118
119
def plot(self, **kwargs: t.Any) -> None:
    """
    Parameters
    ----------
    **kwargs
        Keyword arguments passed to `matplotlib.pyplot.quiver`.
    """
    if self.ax is None:
        if self.fig is None:
            self.fig = plt.figure()
        self.ax = self.fig.add_subplot()

    return self.ax.quiver(self.x, self.y, self.u, self.v, **kwargs)

Example

import numpy as np
from monet_plots.plots import StickPlot

# Create sample data
u = np.random.rand(10)
v = np.random.rand(10)
y = np.arange(10)

# Create the plot
plot = StickPlot(u, v, y)
plot.plot()