File size: 2,562 Bytes
2955ecc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
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
63
64
65
66
67
68
69
70
71
72
73
74
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
#!/usr/bin/env python3
"""Supplementary figure: missing, observed zero, and observed value."""

from __future__ import annotations

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

from style import (
    BLUE,
    COLUMN_WIDTH_IN,
    INK,
    LIGHT_GREY,
    MID_GREY,
    SMALL_TEXT_PT,
    HERE,
    save_figure,
)


OUTPUT = HERE / "fig_missing_zero.pdf"


def main() -> None:
    fig, ax = plt.subplots(figsize=(COLUMN_WIDTH_IN, 1.55))
    fig.subplots_adjust(left=0.34, right=0.98, bottom=0.08, top=0.96)
    ax.set_xlim(0, 5)
    ax.set_ylim(-0.55, 2.65)
    ax.axis("off")

    rows = [
        (2.05, "missing"),
        (1.05, "observed zero"),
        (0.05, "observed value"),
    ]
    for y, label in rows:
        ax.text(-0.08, y, label, ha="right", va="center", clip_on=False)
        ax.add_patch(
            Rectangle(
                (0.20, y - 0.31),
                4.55,
                0.62,
                facecolor="none",
                edgecolor=LIGHT_GREY,
                lw=0.75,
                ls=(0, (3, 2)),
            )
        )

    sample_x = [0.62, 1.52, 2.42, 3.32, 4.22]
    ax.plot([0.32, 4.63], [1.05, 1.05], color=MID_GREY, lw=0.55)
    ax.scatter(sample_x, [1.05] * len(sample_x), s=18, color=BLUE, zorder=3)

    ax.plot([0.32, 4.63], [0.05, 0.05], color=MID_GREY, lw=0.55)
    observed = [0.22, 0.39, 0.27, 0.50, 0.34]
    ax.vlines(sample_x, 0.05, observed, color=BLUE, lw=0.7)
    ax.scatter(sample_x, observed, s=18, color=BLUE, zorder=3)

    ax.annotate(
        "",
        xy=(4.63, -0.42),
        xytext=(0.32, -0.42),
        arrowprops={"arrowstyle": "-|>", "color": MID_GREY, "lw": 0.55},
    )
    ax.text(
        2.48,
        -0.42,
        "time",
        ha="center",
        va="center",
        color=MID_GREY,
        bbox={"facecolor": "white", "edgecolor": "none", "pad": 0.5},
    )

    # A compact key, not a consequence diagram.
    ax.plot([0.30, 0.78], [2.52, 2.52], color=LIGHT_GREY, lw=0.75, ls=(0, (3, 2)))
    ax.text(
        0.88,
        2.52,
        "expected",
        ha="left",
        va="center",
        fontsize=SMALL_TEXT_PT,
        color=MID_GREY,
    )
    ax.scatter([3.55], [2.52], s=18, color=BLUE)
    ax.text(
        3.77,
        2.52,
        "delivered",
        ha="left",
        va="center",
        fontsize=SMALL_TEXT_PT,
        color=MID_GREY,
    )

    save_figure(
        fig,
        OUTPUT,
        subject="Three categorical delivery states for optional telemetry",
    )


if __name__ == "__main__":
    main()