Skip to content

Plot

sereto.plot

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
@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.
    """
    # 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")

    RISKS_CNT = len(risks.names())

    rect = ax.bar(range(RISKS_CNT), risks.counts(), align="center", color=risks.colors())
    ax.set_xticks(range(RISKS_CNT))
    ax.set_xticklabels([r.capitalize() for r in risks.names()])
    ax.set_yticks(range(max(risks.counts()) + 1))
    _label_plot(ax, rect)

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