def plot_year_over_year()

in jobs/desktop-mobile-mau-2020/desktop_mau/desktop_mau_dau.py [0:0]


def plot_year_over_year(full_dat, country):
    """Save a plot for MAU and DAU (7d MA) at country level."""
    dat = full_dat.loc[full_dat.country == country]

    plt.style.use("seaborn-white")
    fig, axs = plt.subplots(nrows=1, ncols=4, figsize=(20, 4), sharex="col")

    metric_list = ["MAU", "mau_pcnt_Jan01", "DAU_MA7d", "dau_pcnt_Jan01"]
    for num, metric in enumerate(metric_list):
        axs[num].set(ylim=(dat[metric].min() * 0.95, dat[metric].max() * 1.05))
        for year in range(2017, 2021):
            axs[num].plot(
                dat.loc[dat["year"] == year, "fakedate"],
                dat.loc[dat["year"] == year, metric],
                label=str(year),
                linestyle="solid",
            )
            axs[num].xaxis.set_major_formatter(mdates.DateFormatter("%b %d"))
            if num % 2 == 0:
                axs[num].yaxis.set_major_formatter(
                    matplotlib.ticker.FuncFormatter(
                        lambda x, pos: "{:,.0f}".format(x / 1000000) + "MM"
                    )
                )
            else:
                axs[num].yaxis.set_major_formatter(
                    matplotlib.ticker.FuncFormatter(
                        lambda x, pos: "{:,.0f}".format(x * 100) + "%"
                    )
                )
            axs[num].legend(
                ("2017", "2018", "2019", "2020"),
                title=country + " " + metric,
                bbox_to_anchor=(0.4, 0.8, 0.6, 0.2),
                loc="upper left",
                ncol=4,
                mode="expand",
                fontsize=9,
            )

    fig.tight_layout()
    axs[0].set_title(
        "Year over Year MAU & DAU(7d MA) in {}".format(country), loc="left", fontsize=18
    )

    filename = f"desktop_{country}_mau_dau.jpeg"
    plt.savefig(IMG_DIR / filename)
    plt.close(fig)
    return filename