Add city plot

This commit is contained in:
Aarni Koskela
2021-02-19 17:56:58 +02:00
parent 41a54d0c6c
commit ce41df75ec
2 changed files with 35 additions and 8 deletions

View File

@@ -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

View File

@@ -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__":