|
| 1 | +import marimo |
| 2 | + |
| 3 | +__generated_with = "0.9.32" |
| 4 | +app = marimo.App(width="full") |
| 5 | + |
| 6 | + |
| 7 | +@app.cell |
| 8 | +def _(): |
| 9 | + import os.path |
| 10 | + import sys |
| 11 | + |
| 12 | + if os.path.dirname(sys.path[0]) not in sys.path: |
| 13 | + sys.path.append(os.path.dirname(sys.path[0])) |
| 14 | + |
| 15 | + import marimo as mo |
| 16 | + import matplotlib as mpl |
| 17 | + import matplotlib.pyplot as plt |
| 18 | + |
| 19 | + import saev.colors |
| 20 | + |
| 21 | + return mo, mpl, os, plt, saev, sys |
| 22 | + |
| 23 | + |
| 24 | +@app.cell |
| 25 | +def __(mpl): |
| 26 | + mpl.font_manager.fontManager.addfont( |
| 27 | + "/System/Library/Fonts/Supplemental/GillSans.ttc" |
| 28 | + ) |
| 29 | + |
| 30 | + mpl.rcParams["font.family"] = "Gill Sans" |
| 31 | + return |
| 32 | + |
| 33 | + |
| 34 | +@app.cell |
| 35 | +def _(plt): |
| 36 | + def barchart(probs: list[tuple[str, float, str]], ylim_max: float): |
| 37 | + labels = [label for label, value, color in probs] |
| 38 | + values = [value for label, value, color in probs] |
| 39 | + colors = [color for label, value, color in probs] |
| 40 | + |
| 41 | + fig, ax = plt.subplots(figsize=(6, 4)) |
| 42 | + ax.bar(labels, values, color=colors, width=0.7) |
| 43 | + |
| 44 | + # Customize the plot |
| 45 | + ax.set_ylabel("Probability (%)", fontsize=13) |
| 46 | + ax.set_ylim(0, ylim_max) |
| 47 | + ax.tick_params(axis="both", which="major", labelsize=16) |
| 48 | + ax.set_axisbelow(True) |
| 49 | + |
| 50 | + # Remove top and right spines |
| 51 | + ax.spines["top"].set_visible(False) |
| 52 | + ax.spines["right"].set_visible(False) |
| 53 | + |
| 54 | + # Adjust layout |
| 55 | + fig.tight_layout() |
| 56 | + |
| 57 | + return fig, ax |
| 58 | + |
| 59 | + return (barchart,) |
| 60 | + |
| 61 | + |
| 62 | +@app.cell |
| 63 | +def _(barchart, saev): |
| 64 | + def bluejay_before(): |
| 65 | + probs_before = [ |
| 66 | + ("Blue Jay", 49.0, saev.colors.CYAN_RGB01), |
| 67 | + ("Clark\nNutcracker", 15.0, saev.colors.SEA_RGB01), |
| 68 | + ("White-Breasted\nNuthatch", 11.0, saev.colors.CREAM_RGB01), |
| 69 | + ("Florida Jay", 7.0, saev.colors.GOLD_RGB01), |
| 70 | + ] |
| 71 | + |
| 72 | + fig, _ = barchart(probs_before, ylim_max=55.0) |
| 73 | + return fig |
| 74 | + |
| 75 | + bluejay_before() |
| 76 | + return (bluejay_before,) |
| 77 | + |
| 78 | + |
| 79 | +@app.cell |
| 80 | +def __(barchart, saev): |
| 81 | + def bluejay_after(): |
| 82 | + probs_after = [ |
| 83 | + ("Clark\nNutcracker", 32.0, saev.colors.SEA_RGB01), |
| 84 | + ("White-Breasted\nNuthatch", 21.0, saev.colors.CREAM_RGB01), |
| 85 | + ("Great Gray\nShrike", 7.0, saev.colors.RUST_RGB01), |
| 86 | + ("Blue Jay", 4.0, saev.colors.BLUE_RGB01), |
| 87 | + ] |
| 88 | + |
| 89 | + fig, _ = barchart(probs_after, ylim_max=55.0) |
| 90 | + return fig |
| 91 | + |
| 92 | + bluejay_after() |
| 93 | + return (bluejay_after,) |
| 94 | + |
| 95 | + |
| 96 | +@app.cell |
| 97 | +def __(barchart, saev): |
| 98 | + def kingbird_before(): |
| 99 | + probs_before = [ |
| 100 | + ("Tropical\nKingbird", 93.0, saev.colors.GOLD_RGB01), |
| 101 | + ("Gray\nKingbird", 4.0, saev.colors.CREAM_RGB01), |
| 102 | + ("Great Crested\nFlycatcher", 1.0, saev.colors.SEA_RGB01), |
| 103 | + ("Sayornis", 1.0, saev.colors.CYAN_RGB01), |
| 104 | + ] |
| 105 | + |
| 106 | + fig, _ = barchart(probs_before, ylim_max=100.0) |
| 107 | + return fig |
| 108 | + |
| 109 | + kingbird_before() |
| 110 | + return (kingbird_before,) |
| 111 | + |
| 112 | + |
| 113 | +@app.cell |
| 114 | +def __(barchart, saev): |
| 115 | + def kingbird_after(): |
| 116 | + probs_before = [ |
| 117 | + ("Gray\nKingbird", 73.0, saev.colors.CREAM_RGB01), |
| 118 | + ("Tropical\nKingbird", 12.0, saev.colors.GOLD_RGB01), |
| 119 | + ("Western\nWood Peewee", 5.0, saev.colors.BLUE_RGB01), |
| 120 | + ("Sayornis", 2.0, saev.colors.CYAN_RGB01), |
| 121 | + ] |
| 122 | + |
| 123 | + fig, _ = barchart(probs_before, ylim_max=100.0) |
| 124 | + return fig |
| 125 | + |
| 126 | + kingbird_after() |
| 127 | + return (kingbird_after,) |
| 128 | + |
| 129 | + |
| 130 | +@app.cell |
| 131 | +def __(barchart, saev): |
| 132 | + def warbler_before(): |
| 133 | + probs_before = [ |
| 134 | + ("Canada\nWarbler", 59.0, saev.colors.SEA_RGB01), |
| 135 | + ("Magnolia\nWarbler", 17.0, saev.colors.CREAM_RGB01), |
| 136 | + ("Wilson\nWarbler", 8.0, saev.colors.GOLD_RGB01), |
| 137 | + ("Kentucky\nWarbler", 3.0, saev.colors.ORANGE_RGB01), |
| 138 | + ] |
| 139 | + |
| 140 | + fig, _ = barchart(probs_before, ylim_max=100.0) |
| 141 | + return fig |
| 142 | + |
| 143 | + warbler_before() |
| 144 | + return (warbler_before,) |
| 145 | + |
| 146 | + |
| 147 | +@app.cell |
| 148 | +def __(barchart, saev): |
| 149 | + def warbler_after(): |
| 150 | + probs = [ |
| 151 | + ("Wilson\nWarbler", 36.0, saev.colors.GOLD_RGB01), |
| 152 | + ("Canada\nWarbler", 32.0, saev.colors.SEA_RGB01), |
| 153 | + ("Magnolia\nWarbler", 9.0, saev.colors.CREAM_RGB01), |
| 154 | + ("Kentucky\nWarbler", 3.0, saev.colors.ORANGE_RGB01), |
| 155 | + ] |
| 156 | + |
| 157 | + fig, _ = barchart(probs, ylim_max=100.0) |
| 158 | + return fig |
| 159 | + |
| 160 | + warbler_after() |
| 161 | + return (warbler_after,) |
| 162 | + |
| 163 | + |
| 164 | +@app.cell |
| 165 | +def __(barchart, saev): |
| 166 | + def finch_before(): |
| 167 | + probs = [ |
| 168 | + ("Purple\nFinch", 83.0, saev.colors.RED_RGB01), |
| 169 | + ("Pine\nGrosbeak", 4.0, saev.colors.RUST_RGB01), |
| 170 | + ("Summer\nTanager", 2.0, saev.colors.ORANGE_RGB01), |
| 171 | + ("Bay-Breasted\nWarbler", 2.0, saev.colors.GOLD_RGB01), |
| 172 | + ] |
| 173 | + |
| 174 | + fig, _ = barchart(probs, ylim_max=100.0) |
| 175 | + return fig |
| 176 | + |
| 177 | + finch_before() |
| 178 | + return (finch_before,) |
| 179 | + |
| 180 | + |
| 181 | +@app.cell |
| 182 | +def __(barchart, saev): |
| 183 | + def finch_after(): |
| 184 | + probs = [ |
| 185 | + ("Field\nSparrow", 14.0, saev.colors.BLUE_RGB01), |
| 186 | + ("Bay-Breasted\nWarbler", 11.0, saev.colors.GOLD_RGB01), |
| 187 | + ("Tree\nSparrow", 5.0, saev.colors.CYAN_RGB01), |
| 188 | + ("Chipping\nSparrow", 4.0, saev.colors.CREAM_RGB01), |
| 189 | + ] |
| 190 | + |
| 191 | + fig, _ = barchart(probs, ylim_max=100.0) |
| 192 | + return fig |
| 193 | + |
| 194 | + finch_after() |
| 195 | + return (finch_after,) |
| 196 | + |
| 197 | + |
| 198 | +@app.cell |
| 199 | +def __(): |
| 200 | + return |
| 201 | + |
| 202 | + |
| 203 | +if __name__ == "__main__": |
| 204 | + app.run() |
0 commit comments