diff --git a/chart_utils.py b/chart_utils.py index 100d654..98bd63d 100644 --- a/chart_utils.py +++ b/chart_utils.py @@ -18,7 +18,7 @@ def set_yaxis_cash(plot): plot.yaxis[0].formatter = bm.NumeralTickFormatter(format="€0") -def get_categorical_stats_plot(df, *, category, value, na_as_category=None): +def get_categorical_stats_plot(df, *, category, value, na_as_category=None, line=True): df = get_categorical_stats(df, category, value, na_as_category=na_as_category) df.reset_index(inplace=True) df[category] = df[category].astype("category") @@ -55,10 +55,30 @@ def get_categorical_stats_plot(df, *, category, value, na_as_category=None): legend_label="q90", color="#ff9f43", ) - plot.line( - df[category], df["median"], legend_label="median", color="#1289A7", line_width=4 - ) - plot.line( - df[category], df["mean"], legend_label="mean", color="#B53471", line_width=4 - ) + if line: + plot.line( + df[category], + df["median"], + legend_label="median", + color="#1289A7", + line_width=4, + ) + plot.line( + df[category], df["mean"], legend_label="mean", color="#B53471", line_width=4 + ) + else: + plot.circle( + df[category], + df["median"], + radius=CAT_Q_RADIUS, + legend_label="median", + color="#1289A7", + ) + plot.circle( + df[category], + df["mean"], + radius=CAT_Q_RADIUS, + legend_label="mean", + color="#B53471", + ) return plot diff --git a/generate_charts.py b/generate_charts.py index deb5a84..6df9729 100644 --- a/generate_charts.py +++ b/generate_charts.py @@ -46,11 +46,18 @@ def plot_sukupuoli_vuositulot(df: DataFrame): ) +@plot_this +def plot_kaupunki_vuositulot(df: DataFrame): + plot = get_categorical_stats_plot(df, category="Kaupunki", value="Vuositulot", line=False) + plot.xaxis.major_label_orientation = "vertical" + return plot + + def main(): df = read_data() plots = [func(df) for func in sorted(plot_funcs, key=lambda f: f.__name__)] bp.output_file("out/charts.html", title="Koodiklinikan Palkkakysely") - bp.save(bl.grid(plots, ncols=2)) + bp.save(bl.grid(plots, ncols=2, sizing_mode="stretch_both")) if __name__ == "__main__":