Пример #1
0
def plot(data):
    agg = {col: "sum" for col in BEDCOUNT_COLUMNS}
    data = data.groupby(["date", "department"]).agg(agg)
    data = data.reset_index()
    data["pct_occ"] = (data["n_covid_occ"] /
                       (data["n_covid_occ"] + data["n_covid_free"])).fillna(0)

    fig, ax = plt.subplots(1, figsize=(7, 4))
    date_idx_range = np.arange(len(data.date.unique()))
    for department, d in data.groupby("department"):
        d = d.sort_values(by="date")
        plot_int(
            date_idx_range,
            d["pct_occ"],
            ax=ax,
            color=DEPARTMENT_COLOR[department],
            label=department,
            lw=2,
        )
    ge_pct_occ = data.groupby("date").pct_occ.mean().sort_index().values
    plot_int(
        date_idx_range,
        ge_pct_occ,
        ax=ax,
        color="k",
        marker=False,
        label="Grand Est",
        lw=4,
    )
    dates = np.array(sorted(data.date.unique().flatten()))
    xticks = np.arange(0, len(dates), 3)
    ax.set_xticks(xticks)
    ax.set_xticklabels(
        [date.strftime("%d-%m") for date in dates[xticks]],
        rotation=45,
    )
    ax.legend(
        ncol=2,
        handles=[
            matplotlib.patches.Patch(
                facecolor=DEPARTMENT_COLOR[department],
                label=department,
                linewidth=3,
            ) for department in sorted(data.department.unique())
        ] + [
            matplotlib.patches.Patch(
                facecolor="k",
                label="Grand Est",
                linewidth=3,
            )
        ],
        loc="lower right",
    )
    ax.set_ylabel("Covid+ beds occupancy percentage")

    tikzplotlib_kwargs = dict(
        axis_width="14cm",
        axis_height="8cm",
    )
    return fig, tikzplotlib_kwargs
Пример #2
0
def plot(data):
    agg = {col: "sum" for col in BEDCOUNT_COLUMNS}
    data = data.groupby(["date"]).agg(agg)
    data = data.sort_index().reset_index()
    data["pct_deaths"] = data["n_covid_deaths"] / (
        data["n_covid_deaths"] + data["n_covid_healed"]
    )
    data["pct_healed"] = data["n_covid_healed"] / (
        data["n_covid_healed"] + data["n_covid_deaths"]
    )
    fig, ax = plt.subplots(1, figsize=(7, 4))
    for col in ["pct_deaths", "pct_healed"]:
        plot_int(
            np.arange(len(data)),
            data[col],
            ax=ax,
            color=COL_COLOR[col],
            label=COLUMN_TO_HUMAN_READABLE[col],
            marker=next(RANDOM_MARKERS),
            lw=2,
        )
    dates = np.array(sorted(data.date.unique().flatten()))
    xticks = np.arange(0, len(dates), 3)
    ax.set_xticks(xticks)
    ax.set_xticklabels(
        [date.strftime("%d-%m") for date in dates[xticks]], rotation=45,
    )
    ax.set_ylabel("Percentage")
    ax.legend()
    tikzplotlib_kwargs = dict(axis_width="14cm", axis_height="6cm",)
    return fig, tikzplotlib_kwargs
Пример #3
0
def plot(data):
    fig, (ax1, ax2) = plt.subplots(2, figsize=(10, 10), sharex=True)
    date_range_idx = np.arange(len(data.date.unique()))
    for dept, dg in data.groupby("department"):
        dg = dg.sort_values(by="date")
        plot_int(
            x=date_range_idx,
            y=dg.n_hospitalised_patients / dg.department_pop * 100e3,
            ax=ax1,
            marker=None,
            color=DEPARTMENT_COLOR[dept],
            label=dept,
            lw=2,
        )
        y1 = dg.n_icu_patients_icubam / dg.department_pop * 100e3
        plot_int(
            x=date_range_idx,
            y=y1,
            ax=ax2,
            marker=None,
            color=DEPARTMENT_COLOR[dept],
            ls="dashed",
            lw=2,
        )
        y2 = dg.n_icu_patients_public / dg.department_pop * 100e3
        plot_int(
            x=date_range_idx,
            y=y2,
            ax=ax2,
            marker=None,
            color=DEPARTMENT_COLOR[dept],
            ls="solid",
            label=dept,
            lw=2,
        )
        ax2.fill_between(
            x=date_range_idx,
            y1=y1,
            y2=y2,
            facecolor=DEPARTMENT_COLOR[dept],
            alpha=0.3,
        )

    ax1.set_ylabel("Population-normalised nb of hospitalised patients")
    ax1.set_title(
        "Evolution of nb of hospitalised patients / 100,000 inhabitants")
    ax1.legend(ncol=2)
    ax2.set_ylabel("Population-normalised nb of ICU patients")
    ax2.set_title("Evolution of nb of ICU patients / 100,000 inhabitants")
    dates = np.array(sorted(data.date.unique().flatten()))
    xticks = np.arange(0, len(dates), 3)
    for ax in [ax1, ax2]:
        ax.set_xticks(xticks)
        ax.set_xticklabels(
            [date.strftime("%d-%m") for date in dates[xticks]],
            rotation=45,
        )
    ax2.legend(
        [
            matplotlib.lines.Line2D([0], [0], color="k", lw=2, ls="solid"),
            matplotlib.lines.Line2D([0], [0], color="k", lw=2, ls="dashed"),
        ],
        ["Public data", "ICUBAM data"],
        ncol=1,
    )
    ax2.set_xlim(0, len(date_range_idx) - 1)
    tikzplotlib_kwargs = dict(
        axis_width="12cm",
        axis_height="8cm",
    )
    return fig, tikzplotlib_kwargs
Пример #4
0
def plot(data):
    agg = {col: "sum" for col in BEDCOUNT_COLUMNS}
    data = data.groupby(["date", "department"]).agg(agg)
    data = data.reset_index()

    data = compute_flow_per_dpt(data)

    fig, ax = plt.subplots(1, figsize=(7, 4))

    date_idx_range = np.arange(len(data.date.unique()))
    sorted_depts = list(
        data.groupby("department").cum_flow.max().sort_values(
            ascending=False).reset_index().department)
    for i, department in enumerate(sorted_depts):
        y = (data.loc[data.department.isin(
            sorted_depts[i:])].groupby("date").flow.sum().sort_index().values)
        plot_int(
            date_idx_range,
            y,
            ax=ax,
            color=DEPARTMENT_COLOR[department],
            label=department,
            lw=1,
            fill_below=True,
        )
        if i == 0:
            plot_int(
                date_idx_range,
                y,
                ax=ax,
                color="black",
                label="Grand Est",
                lw=3,
            )
    dates = np.array(sorted(data.date.unique().flatten()))
    xticks = np.arange(0, len(dates), 3)
    ax.set_xticks(xticks)
    ax.set_xticklabels(
        [date.strftime("%d-%m") for date in dates[xticks]],
        rotation=45,
    )
    ax.legend(
        ncol=2,
        handles=[
            matplotlib.patches.Patch(
                facecolor=DEPARTMENT_COLOR[dpt],
                label=dpt,
                linewidth=3,
            ) for dpt in sorted_depts
        ] + [
            matplotlib.patches.Patch(
                facecolor="black",
                label="Grand Est",
                linewidth=1,
            )
        ],
        loc="upper left",
    )
    tikzplotlib_kwargs = dict(
        axis_width="14cm",
        axis_height="8cm",
    )
    return fig, tikzplotlib_kwargs
Пример #5
0
def plot(data):
    n_occ = data.groupby("date").sum()["n_covid_occ"]
    n_free = data.groupby("date").sum()["n_covid_free"]
    n_transfered = (
        data.groupby("date").sum()["n_covid_transfered"].diff(1).fillna(0))
    n_tot = n_occ + n_free
    n_req = n_occ + n_transfered
    fig, ax = plt.subplots(1, figsize=(18, 12))

    x_icubam_beg = np.argwhere(
        np.sort(data.date.unique()) == datetime.date(2020, 3, 25)).flatten()[0]
    ax.axvline(x=x_icubam_beg, c="red", lw=7, ls="dashed")
    text = ax.text(
        x=x_icubam_beg - 0.5,
        y=n_tot.max() * 0.95,
        s=r"Start \texttt{ICUBAM}",
        fontsize="xx-large",
        fontweight="bold",
        color="red",
    )
    text.set_horizontalalignment("right")

    date_range_idx = np.arange(len(n_req))

    ax = plot_int(
        date_range_idx,
        n_tot.values,
        ax=ax,
        color=next(RANDOM_COLORS),
        marker=next(RANDOM_MARKERS),
        label="Total (beds)",
        lw=2,
    )
    ax = plot_int(
        date_range_idx,
        n_req.values,
        ax=ax,
        color=next(RANDOM_COLORS),
        marker=next(RANDOM_MARKERS),
        label="Nb of occupied beds + transfers",
        lw=2,
    )
    ax = plot_int(
        date_range_idx,
        n_occ.values,
        ax=ax,
        color=next(RANDOM_COLORS),
        marker=next(RANDOM_MARKERS),
        label="Nb of occupied beds",
        lw=2,
    )
    ax.set_ylabel("Number of patients / beds")
    ax.legend(loc="lower right")
    dates = np.array(sorted(data.date.unique().flatten()))
    xticks = np.arange(0, len(dates), 3)
    ax.set_xticks(xticks)
    ax.set_xticklabels(
        [date.strftime("%d-%m") for date in dates[xticks]],
        rotation=45,
    )
    tikzplotlib_kwargs = dict(
        axis_width="13.5cm",
        axis_height="7.2cm",
    )
    return fig, tikzplotlib_kwargs