Skip to content

pymdea.plot

Plotting functions.

DeaPlotter(model, theme=None)

Plot DEA results.

Parameters:

  • model

    (Self @ DeaEngine) –

    Object containing the results of a DEA analysis to be plotted.

  • theme

    (None | str, default: None ) –

    Must be either None or a string corresponding to a matplotlib.pyplot style.

Source code in src/pymdea/plot.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
def __init__(
    self: Self,
    model: DeaEngine,
    theme: None | str = None,
) -> Self:
    """Plot DEA results.

    Parameters
    ----------
    model : Self@DeaEngine
        Object containing the results of a DEA analysis to be plotted.
    theme : None | str, optional, default: None
        Must be either None or a string corresponding to a
        matplotlib.pyplot style.

    """
    if theme is not None:
        plt.style.use(style=theme)
    self.window_lengths = model.window_lengths
    self.entropies = model.entropies
    self.delta = model.fit_coefficients[0]
    self.y_intercept = model.fit_coefficients[1]
    self.mu1 = model.mu1
    self.mu2 = model.mu2
    self.mu3 = model.mu3

mu_candidates(fig_width=5, fig_height=3)

Plot the possible values of mu.

Parameters:

  • fig_width

    (int, default: 4 ) –

    Width, in inches, of the figure.

  • fig_height

    (int, default: 3 ) –

    Height, in inches, of the figure.

Source code in src/pymdea/plot.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def mu_candidates(self: Self, fig_width: int = 5, fig_height: int = 3) -> None:
    """Plot the possible values of mu.

    Parameters
    ----------
    fig_width : int, optional, default: 4
        Width, in inches, of the figure.
    fig_height : int, optional, default: 3
        Height, in inches, of the figure.

    """
    x1 = np.linspace(1, 2, 100)
    x2 = np.linspace(2, 3, 100)
    x3 = np.linspace(3, 4, 100)
    y1 = x1 - 1
    y2 = 1 / (x2 - 1)
    y3 = np.full(100, 0.5)

    fig, ax = plt.subplots(figsize=(fig_width, fig_height), layout="constrained")
    ax.plot(x1, y1, color="k")
    ax.plot(x2, y2, color="k")
    ax.plot(x3, y3, color="k")
    ax.plot(
        self.mu1,
        self.delta,
        marker="o",
        fillstyle="none",
        markersize=5,
        markeredgewidth=2,
        linestyle="none",
        label=f"$\\mu$ = {np.round(self.mu1, 2)}",
    )
    ax.plot(
        self.mu2,
        self.delta,
        marker="o",
        fillstyle="none",
        markersize=5,
        markeredgewidth=2,
        linestyle="none",
        label=f"$\\mu$ = {np.round(self.mu2, 2)}",
    )
    ax.plot(
        self.mu3,
        self.delta,
        marker="o",
        fillstyle="none",
        markersize=5,
        markeredgewidth=2,
        linestyle="none",
        label=f"$\\mu$ = {np.round(self.mu3, 2)}",
    )
    ax.set_xticks(ticks=np.linspace(1, 4, 7))
    ax.set_yticks(ticks=np.linspace(0, 1, 5))
    ax.set_xlabel("$\\mu$")
    ax.set_ylabel("$\\delta$")
    ax.legend(loc="center left", bbox_to_anchor=(1.0, 0.5))
    ax.grid(visible=True)
    sns.despine(left=True, bottom=True)
    self.fig_mu_candidates = fig

s_vs_l(fig_width=5, fig_height=3)

Plot the slope of entropy vs window length.

Parameters:

  • fig_width

    (int, default: 4 ) –

    Width, in inches, of the figure.

  • fig_height

    (int, default: 3 ) –

    Height, in inches, of the figure.

Source code in src/pymdea/plot.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def s_vs_l(self: Self, fig_width: int = 5, fig_height: int = 3) -> None:
    """Plot the slope of entropy vs window length.

    Parameters
    ----------
    fig_width : int, optional, default: 4
        Width, in inches, of the figure.
    fig_height : int, optional, default: 3
        Height, in inches, of the figure.

    """
    x_line = np.linspace(start=1, stop=np.max(self.window_lengths), num=3)
    fig, ax = plt.subplots(figsize=(fig_width, fig_height), layout="constrained")
    ax.plot(
        self.window_lengths,
        self.entropies,
        linestyle="none",
        marker="o",
        markersize=3,
        fillstyle="none",
    )
    ax.plot(
        x_line,
        self.delta * np.log(x_line) + self.y_intercept,
        color="k",
        label=f"$\\delta = {np.round(self.delta, 3)}$",
    )
    ax.set_xscale("log")
    ax.set_xlabel("$\\ln(L)$")
    ax.set_ylabel("$S(L)$")
    ax.legend(loc="center left", bbox_to_anchor=(1.0, 0.5))
    sns.despine(trim=True)
    self.fig_s_vs_l = fig