Skip to content

Plot

sereto.plot

_label_plot(ax, rect)

Add labels to the bars in the bar plot.

Parameters:

Name Type Description Default
ax Axes

Object containing the bar plot.

required
rect BarContainer

Object containing the bars in the bar plot.

required
Source code in sereto/plot.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def _label_plot(ax: Axes, rect: BarContainer) -> None:
    """Add labels to the bars in the bar plot.

    Args:
        ax: Object containing the bar plot.
        rect: Object containing the bars in the bar plot.
    """
    for r in rect:
        height = r.get_height()
        if height > 0:
            ax.annotate(
                str(height),
                xy=(r.get_x() + r.get_width() / 2, height),
                xytext=(0, 3),  # 3 points vertical offset
                textcoords="offset points",
                ha="center",
                va="bottom",
            )

risks_plot(risks, path)

Generate a bar plot with the number of vulnerabilities per risk rating.

Parameters:

Name Type Description Default
risks Risks

Object containing the counts of vulnerabilities for each risk rating.

required
path Path

Desired destination for the generated PNG file.

required
Source code in sereto/plot.py
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
@validate_call
def risks_plot(risks: Risks, path: Path) -> None:
    """Generate a bar plot with the number of vulnerabilities per risk rating.

    Args:
        risks: Object containing the counts of vulnerabilities for each risk rating.
        path: Desired destination for the generated PNG file.
    """
    NAMES = ["Critical", "High", "Medium", "Low", "Info"]
    COUNTS = [risks.critical, risks.high, risks.medium, risks.low, risks.info]
    COLORS = ["red", "orange", "#f0f000", "#33cc33", "#3366ff"]

    # Set global font size
    rcParams["font.size"] = 14

    fig, ax = plt.subplots()
    fig.set_size_inches(10, 5)
    ax.set_title("Number of Vulnerabilities by Risk Rating")

    rect = ax.bar(range(len(NAMES)), COUNTS, align="center", color=COLORS)
    ax.set_xticks(range(len(NAMES)))
    ax.set_xticklabels(NAMES)
    ax.set_yticks(range(max(risks.critical, risks.high, risks.medium, risks.low, risks.info) + 1))
    _label_plot(ax, rect)

    fig.tight_layout()
    plt.margins(0.15)
    plt.savefig(path, dpi=100)
    plt.close("all")