def plot_district_age_distribution(percentiles, ylabel, fmt, phi=50, vax_policy="random", N_jk=None, n=5, district_spacing=1.5, age_spacing=0.1, rotation=0): fig = plt.figure() district_ordering = list(districts_to_run.index)[:n] for (i, district) in enumerate(district_ordering): ylls = percentiles[district, phi, vax_policy] for j in range(7): plt.errorbar(x=[district_spacing * i + age_spacing * (j - 3)], y=ylls[1, 6 - j] * USD / (N_jk[f"N_{6-j}"][district] if N_jk else 1), yerr=[[(ylls[1, 6 - j] - ylls[0, 6 - j]) * USD / (N_jk[f"N_{6-j}"][district] if N_jk else 1)], [(ylls[2, 6 - j] - ylls[1, 6 - j]) * USD / (N_jk[f"N_{6-j}"][district] if N_jk else 1)]], fmt=fmt, color=age_group_colors[6 - j], figure=fig, label=None if i > 0 else age_bin_labels[6 - j], ms=12, elinewidth=5) plt.xticks([1.5 * _ for _ in range(n)], district_ordering, rotation=rotation, fontsize="20") plt.yticks(fontsize="20") plt.legend(title="age bin", title_fontsize="20", fontsize="20", ncol=7, loc="lower center", bbox_to_anchor=(0.5, 1)) ymin, ymax = plt.ylim() plt.vlines(x=[0.75 + 1.5 * _ for _ in range(n - 1)], ymin=ymin, ymax=ymax, color="gray", alpha=0.5, linewidths=2) plt.ylim(ymin, ymax) plt.gca().grid(False, axis="x") plt.PlotDevice().title(f"\n{vax_policy} demand curves").ylabel( f"{ylabel}\n")
def plot_state_age_distribution(percentiles, ylabel, fmt, district_spacing=1.5, n=5, age_spacing=0.1, rotation=0, ymin=0, ymax=1000): fig = plt.figure() state_ordering = list( sorted(percentiles.keys(), key=lambda k: percentiles[k][0].max(), reverse=True)) for (i, state) in enumerate(state_ordering[:n]): ylls = percentiles[state] for j in range(7): plt.errorbar(x=[district_spacing * i + age_spacing * (j - 3)], y=ylls[0, 6 - j], yerr=[[(ylls[0, 6 - j] - ylls[1, 6 - j])], [(ylls[2, 6 - j] - ylls[0, 6 - j])]], fmt=fmt, color=agebin_colors[6 - j], figure=fig, label=None if i > 0 else agebin_labels[6 - j], ms=12, elinewidth=5) plt.xticks([1.5 * _ for _ in range(n)], state_ordering, rotation=rotation, fontsize="20") plt.yticks(fontsize="20") # plt.legend(title = "age bin", title_fontsize = "20", fontsize = "20", ncol = 7, plt.legend(fontsize="20", ncol=7, loc="lower center", bbox_to_anchor=(0.5, 1)) plt.vlines(x=[0.75 + 1.5 * _ for _ in range(n - 1)], ymin=ymin, ymax=ymax, color="gray", alpha=0.5, linewidths=4) plt.ylim(ymin, ymax) plt.gca().grid(False, axis="x") plt.PlotDevice().ylabel(f"{ylabel}\n")
def outcomes_per_policy(percentiles, metric_label, fmt, phis=[25, 50, 100, 200], reference=(25, "no_vax"), reference_color=no_vax_color, vax_policies=["contact", "random", "mortality"], policy_colors=[ contactrate_vax_color, random_vax_color, mortality_vax_color ], policy_labels=[ "contact rate priority", "random assignment", "mortality priority" ], spacing=0.2): fig = plt.figure() md, lo, hi = percentiles[reference] *_, bars = plt.errorbar(x=[0], y=[md], yerr=[[md - lo], [hi - md]], figure=fig, fmt=fmt, color=reference_color, label="no vaccination", ms=12, elinewidth=5) [_.set_alpha(0.5) for _ in bars] plt.hlines(md, xmin=-1, xmax=5, linestyles="dotted", colors=reference_color) for (i, phi) in enumerate(phis, start=1): for (j, (vax_policy, color, label)) in enumerate( zip(vax_policies, policy_colors, policy_labels)): md, lo, hi = death_percentiles[phi, vax_policy] *_, bars = plt.errorbar(x=[i + spacing * (j - 1)], y=[md], yerr=[[md - lo], [hi - md]], figure=fig, fmt=fmt, color=color, label=label if i == 0 else None, ms=12, elinewidth=5) [_.set_alpha(0.5) for _ in bars] plt.legend(ncol=4, fontsize="20", loc="lower center", bbox_to_anchor=(0.5, 1)) plt.xticks(range(len(phis) + 1), [f"$\phi = {phi}$%" for phi in ([0] + phis)], fontsize="20") plt.yticks(fontsize="20") plt.PlotDevice().ylabel(f"{metric_label}\n") plt.gca().grid(False, axis="x") ymin, ymax = plt.ylim() plt.vlines(x=[0.5 + _ for _ in range(len(phis))], ymin=ymin, ymax=ymax, color="gray", alpha=0.5, linewidths=2) plt.ylim(ymin, ymax) plt.xlim(-0.5, len(phis) + 1.5)
Rt_dist = { k: v for (k, v) in sorted(Rt_dist.items(), key=lambda e: e[1][0], reverse=True) if v != [0, 0, 0] } md, hi, lo = map(np.array, list(zip(*Rt_dist.values()))) *_, bars = plt.errorbar( # x = [-2] + list(range(len(md))), x=list(range(len(md))), # y = np.r_[Rt_TTn, md], y=md, # yerr = [ # np.r_[Rt_TTn - Rt_CI_lower_TTn, md - lo], # np.r_[Rt_CI_upper_TTn - Rt_TTn, hi - md] # ], yerr=[md - lo, hi - md], fmt="s", color=plt.BLK, ms=8, elinewidth=10, label="$R_t$ (95% CI)") [_.set_alpha(0.3) for _ in bars] # plt.hlines(Rt_TTn, xmin = -3, xmax = len(md) + 1, linestyles = "dotted", colors = plt.BLK) # plt.vlines(-1, ymin = 0, ymax = 6, linewidth = 3, colors = "black") plt.ylim(bottom=0, top=6) # plt.xlim(left = -3, right = len(md)) plt.xlim(left=-1, right=len(md)) plt.PlotDevice().ylabel("reproductive rate ($R_t$)\n").xlabel("\nstate") # plt.xticks(ticks = [-2] + list(range(len(md))), labels = ["India"] + [state_name_lookup[_][:2] for _ in Rt_dist.keys()], fontsize = "20")
zip( [ contact_percentiles, ], # random_percentiles, mortality_percentiles], [ contactrate_vax_color, ] # random_vax_color, mortality_vax_color] )): for (i, (key, (lo, md, hi))) in enumerate(metrics.items()): *_, bars = plt.errorbar( x=[i], y=[md], yerr=[[md - lo], [hi - md]], figure=fig, fmt="o", color=clr, label=None if i > 0 else [ "contact rate prioritized", "random assignment", "mortality prioritized" ][dx], ms=12, elinewidth=5) [_.set_alpha(0.5) for _ in bars] plt.xticks( range(len(metrics)), [f"{phi}%" for phi in (100 * (10**np.linspace(-1, 1, 11))).round(0)], fontsize="20") plt.yticks(fontsize="20") plt.PlotDevice().ylabel("deaths\n").xlabel( "\npercentage of population vaccinated annually") # plt.ylim(200, 450)
for (k, v) in evaluated_death_percentiles.items() if "mortality" in k } novax_percentiles = { k: v for (k, v) in evaluated_death_percentiles.items() if "novacc" in k } fig = plt.figure() *_, bars = plt.errorbar(x=[-1], y=novax_percentiles["novaccination"][1], yerr=[ novax_percentiles["novaccination"][1] - [novax_percentiles["novaccination"][0]], [ novax_percentiles["novaccination"][2] - novax_percentiles["novaccination"][1] ] ], fmt="o", color=no_vax_color, label="no vaccination", figure=fig, ms=12, elinewidth=5) [_.set_alpha(0.5) for _ in bars] for (dx, (metrics, clr)) in enumerate( zip([contact_percentiles, random_percentiles, mortality_percentiles], [contactrate_vax_color, random_vax_color, mortality_vax_color])): for (i, (key, (lo, md, hi))) in enumerate(metrics.items()): *_, bars = plt.errorbar( x=[i + 0.2 * (dx - 1)],