Skip to content

pymdea.plot

Plotting functions.

DeaPlotter(model, theme='ticks', colors='muted')

Plot DEA results.

Parameters:

  • model (Self @ DeaEngine) –

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

  • theme (str {"ticks", "whitegrid", "darkgrid"}, default: "ticks" ) –

    Name of a seaborn style. Passed through to seaborn.set_theme().

  • colors (str {"muted", "deep", "Set2", "tab10"}, default: "muted" ) –

    Name of a seaborn or matplotlib color palette. Passed through to seaborn.set_theme().

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
40
41
def __init__(
    self: Self,
    model: DeaEngine,
    theme: Literal["ticks", "whitegrid", "darkgrid"] = "ticks",
    colors: Literal["muted", "deep", "Set2", "tab10"] = "muted",
) -> Self:
    """Plot DEA results.

    Parameters
    ----------
    model : Self@DeaEngine
        Object containing the results of a DEA analysis to be plotted.
    theme : str {"ticks", "whitegrid", "darkgrid"}, optional, default: "ticks"
        Name of a seaborn style. Passed through to
        seaborn.set_theme().
    colors : str {"muted", "deep", "Set2", "tab10"}, optional, default: "muted"
        Name of a seaborn or matplotlib color palette. Passed
        through to seaborn.set_theme().

    """
    sns.set_theme(context="notebook", style=theme, palette=colors)
    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

mu_candidates(fig_width=4, 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
 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
def mu_candidates(self: Self, fig_width: int = 4, 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))
    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.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=0)
    ax.grid(visible=True)
    sns.despine(left=True, bottom=True)
    plt.show(fig)

s_vs_l(fig_width=4, 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
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
74
75
def s_vs_l(self: Self, fig_width: int = 4, 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))
    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=0)
    sns.despine(trim=True)
    plt.show(fig)