scripts/scatter_plots.py
def plot_vs_area(districts_budget_df):
    """
    From district budget to scatter plots vs area size
    """
    for q in districts_budget_df.budget_type.unique():
        df = districts_budget_df.query("budget_type == '{}'".format(q))
        df = df.groupby(["dname", "AREA"])["budget"].sum().reset_index()
        source = ColumnDataSource(
            data=dict(
                x=df["AREA"] / 1000000, y=df["budget"] / 1000000, desc=df["dname"]
            )
        )
        p = figure(title="", tools="hover,box_zoom,reset")
        vline = Span(
            location=df.AREA.mean() / 1000000,
            dimension="height",
            line_color="gold",
            line_width=1.5,
        )
        hline = Span(
            location=df["budget"].mean() / 1000000,
            dimension="width",
            line_color="gold",
            line_width=1.5,
        )

        p.circle(
            "x", "y", source=source, fill_alpha=0.2, size=10,
        )

        p.xaxis.axis_label = "ขนาดพื้นที่ (ตร.กม.)"
        p.yaxis.axis_label = f"งบประมาณ{q} (ล้านบาท)"
        p.xaxis.axis_label_text_font_size = "15pt"
        p.yaxis.axis_label_text_font_size = "15pt"
        p.xaxis.major_label_text_font_size = "12pt"
        p.yaxis.major_label_text_font_size = "12pt"

        hover = HoverTool(
            tooltips=[
                ("เขต", "@desc"),
                (f"งบ{q}", "@y ล้านบาท"),
                ("ขนาดพื้นที่", "@x ตร.กม."),
            ]
        )
        p.add_tools(hover)
        p.renderers.extend([vline, hline])
        output_file(f"plots/scatter-{q_map[q]}-budget-area.html", mode="inline")
        save(p)

    From district budget to scatter plots vs area size
    
From district budget to scatter plots vs area size
From district budget to scatter plots vs area size
def plot_vs_area(districts_budget_df):
    for q in districts_budget_df.budget_type.unique():
        df = districts_budget_df.query("budget_type == '{}'".format(q))
        df = df.groupby(["dname", "AREA"])["budget"].sum().reset_index()
        source = ColumnDataSource(
            data=dict(
                x=df["AREA"] / 1000000, y=df["budget"] / 1000000, desc=df["dname"]
            )
        )
        p = figure(title="", tools="hover,box_zoom,reset")
        vline = Span(
            location=df.AREA.mean() / 1000000,
            dimension="height",
            line_color="gold",
            line_width=1.5,
        )
        hline = Span(
            location=df["budget"].mean() / 1000000,
            dimension="width",
            line_color="gold",
            line_width=1.5,
        )
        p.circle(
            "x", "y", source=source, fill_alpha=0.2, size=10,
        )
        p.xaxis.axis_label = "ขนาดพื้นที่ (ตร.กม.)"
        p.yaxis.axis_label = f"งบประมาณ{q} (ล้านบาท)"
        p.xaxis.axis_label_text_font_size = "15pt"
        p.yaxis.axis_label_text_font_size = "15pt"
        p.xaxis.major_label_text_font_size = "12pt"
        p.yaxis.major_label_text_font_size = "12pt"
        hover = HoverTool(
            tooltips=[
                ("เขต", "@desc"),
                (f"งบ{q}", "@y ล้านบาท"),
                ("ขนาดพื้นที่", "@x ตร.กม."),
            ]
        )
        p.add_tools(hover)
        p.renderers.extend([vline, hline])
        output_file(f"plots/scatter-{q_map[q]}-budget-area.html", mode="inline")
        save(p)
def plot_vs_area ( districts_budget_df ) : for q in districts_budget_df . budget_type . unique ( ) : df = districts_budget_df . query ( "budget_type == '{}'" . format ( q ) ) df = df . groupby ( [ "dname" , "AREA" ] ) [ "budget" ] . sum ( ) . reset_index ( ) source = ColumnDataSource ( data = dict ( x = df [ "AREA" ] / 1000000 , y = df [ "budget" ] / 1000000 , desc = df [ "dname" ] ) ) p = figure ( title = "" , tools = "hover,box_zoom,reset" ) vline = Span ( location = df . AREA . mean ( ) / 1000000 , dimension = "height" , line_color = "gold" , line_width = 1.5 , ) hline = Span ( location = df [ "budget" ] . mean ( ) / 1000000 , dimension = "width" , line_color = "gold" , line_width = 1.5 , ) p . circle ( "x" , "y" , source = source , fill_alpha = 0.2 , size = 10 , ) p . xaxis . axis_label = "ขนาดพื้นที่ (ตร.กม.)" p . yaxis . axis_label = f"งบประมาณ{q} (ล้านบาท)" p . xaxis . axis_label_text_font_size = "15pt" p . yaxis . axis_label_text_font_size = "15pt" p . xaxis . major_label_text_font_size = "12pt" p . yaxis . major_label_text_font_size = "12pt" hover = HoverTool ( tooltips = [ ( "เขต", "@de s "), ( f"งบ{q}", "@ y ล้านบาท"), ( "ขนาดพื้นที่", "@x ตร.กม."), ] ) p . add_tools ( hover ) p . renderers . extend ( [ vline , hline ] ) output_file ( f"plots/scatter-{q_map[q]}-budget-area.html" , mode = "inline" ) save ( p )
From district budget to scatter plots vs area size
From district budget to scatter plots vs area size
"""
    From district budget to scatter plots vs area size
    """
districts_budget_df