예제 #1
0
    def make_plot(src):
        p = figure(
            plot_width=1000,
            plot_height=400,
            x_range=src.data["x_range"],
            y_range=(0, 360000),
            tooltips="$name: @$name{0€} €",
        )

        y_list = src.column_names
        y_list.remove("x_range")

        # Define static styling options
        hatch_pattern = [
            " ",
            " ",
            "/",
            " ",
            " ",
            " ",
            "/",
            "/",
            "/",
            " ",
            " ",
            "/",
            " ",
            "/",
        ]
        color = [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#ff7f0e",
            "#ffbb78",
            "#ffbb78",
            "#ffbb78",
            "#ffbb78",
            "#2ca02c",
            "#2ca02c",
            "#98df8a",
            "#98df8a",
            "#2ca02c",
            "#2ca02c",
        ]
        renderers = p.vbar_stack(
            y_list,
            x="x_range",
            width=0.5,
            source=src,
            color=color,
            hatch_pattern=hatch_pattern,
            line_color=None,
        )

        labels = [
            "Capital income",
            "Labor income",
            "Capital income deduction",
            "Taxable capital income",
            "Taxable labor income",
            "Taxable total income",
            "Labor income deduction",
            "Total income deduction",
            "Capital income tax",
            "Net capital income",
            "Net labor income",
            "Labor income tax",
            "Net total income",
            "Total income tax",
        ]

        legend = Legend(
            items=[(labels[count], [r]) for count, r in enumerate(renderers)],
            location="center",
        )

        p.add_layout(legend, "right")

        # Table to display source data

        columns = [TableColumn(field="x_range", title="Bar")
                   ] + [TableColumn(field=i, title=i) for i in y_list]

        data_table = DataTable(
            source=src,
            columns=columns,
            width=900,
            height=200,
            index_position=None,
            autosize_mode="fit_columns",
        )

        plot = plotstyle(p, plot_dict)

        return plot, data_table
예제 #2
0
    def setup_plot(src_heatmap, src_household, line_source_dict):
        colors = Turbo256[145:256]
        colors = list(colors)
        mapper = LinearColorMapper(
            palette=colors,
            low=min(src_heatmap.data["Change to tax burden"]),
            high=max(src_heatmap.data["Change to tax burden"]),
        )

        # Actual figure setup
        p = figure(
            plot_width=800,
            plot_height=400,
            x_range=(0, 310000),
            y_range=(0, 100000),
            tools="save",
        )

        p.rect(
            x="Labor income",
            y="Capital income",
            width=3000,
            height=1000,
            source=src_heatmap,
            line_color=None,
            fill_color=transform("Change to tax burden", mapper),
        )

        p.scatter(
            x="labor_income", y="capital_income", source=src_household, color="black"
        )

        labels = LabelSet(
            x="labor_income",
            y="capital_income",
            text="deciles",
            x_offset=-15,
            y_offset=5,
            source=src_household,
        )

        color_bar = ColorBar(
            color_mapper=mapper,
            location=(0, 0),
            ticker=BasicTicker(desired_num_ticks=20),
            formatter=NumeralTickFormatter(format="0€"),
            label_standoff=12,
            title="Impact (in €)",
        )

        p.add_layout(color_bar, "right")
        p.add_layout(labels)

        for i in line_source_dict.keys():
            i = p.line(
                x="Labor income",
                y="Capital income",
                source=line_source_dict[i],
                line_width=1,
                line_color="grey",
                name=str(i),
            )

        hover = HoverTool(
            tooltips=[
                ("Impact to tax burden", "@{Change to tax burden}{0€} €"),
                ("Taxable labor income", "$x{0€} €"),
                ("Taxable capital income", "$y{0€} €"),
            ],
            names=[str(i) for i in line_source_dict.keys()],
        )
        p.add_tools(hover)

        p.xaxis.tags = ["numeric"]

        plot = plotstyle(p, plot_dict)

        return plot
예제 #3
0
    def make_plot(src, src2):
        # plot 1
        p = figure(
            plot_width=800,
            plot_height=400,
            x_range=FactorRange(*src.data["factor"]),
            tooltips="@factor: @change{0€} €",
        )

        p.vbar(
            x="factor",
            top="change",
            width=0.8,
            source=src,
            fill_color=factor_cmap(
                "factor",
                palette=Category10[4][1:],
                factors=["delta_tax_base", "externalities", "total"],
                start=1,
                end=2,
            ),
            line_color=None,
        )

        labels = LabelSet(
            x="factor",
            y="change",
            text="label",
            source=src,
            render_mode="canvas",
            y_offset=-7,
        )

        p.add_layout(labels)

        p.xgrid.grid_line_color = None

        # Static styling
        p.x_range.range_padding = 0.1
        p.xaxis.major_label_orientation = 1.4

        plot = plotstyle(p, plot_dict1)

        # Plot 2
        p2 = figure(
            plot_width=800,
            plot_height=400,
            y_range=src2.data["deciles"],
            x_range=[-180, 187],
            tooltips="@deciles: @aggr_delta_after_eti{0€} Mio.€",
        )

        labels2 = LabelSet(
            x="aggr_delta_after_eti",
            y="deciles",
            text="label",
            source=src2,
            x_offset="offset",
            y_offset=-10,
            render_mode="canvas",
        )

        color_mapper = LinearColorMapper(
            palette=RdYlGn[10],
            low=max(src2.data["aggr_delta_after_eti"]),
            high=min(src2.data["aggr_delta_after_eti"]),
        )

        p2.hbar(
            y="deciles",
            right="aggr_delta_after_eti",
            source=src2,
            height=0.8,
            color={
                "field": "aggr_delta_after_eti",
                "transform": color_mapper
            },
            line_color=None,
        )

        p2.add_layout(labels2)

        p2.xaxis.tags = ["numeric"]
        p2.yaxis.tags = ["categorical"]

        plot2 = plotstyle(p2, plot_dict2)

        return plot, plot2
예제 #4
0
    def make_plot(src, src_raw):
        p = figure(plot_width=800, plot_height=400, tooltips="$name: $y{0.00%} ",)

        lines = [
            "deciles",
            "total_income_share",
            "labor_income_share",
            "capital_income_share",
            "net_income_share",
        ]
        labels = [
            "Perfect equality",
            "Total income (pre tax)",
            "Labor income (pre tax)",
            "Capital income (pre tax)",
            "Total income (after tax)",
        ]
        colors = Category10[len(lines)]

        for i in range(len(lines)):
            p.line(
                "deciles",
                lines[i],
                source=src,
                line_color=colors[i],
                legend_label=labels[i],
                alpha=0.8,
                muted_color=colors[i],
                muted_alpha=0.2,
                name=labels[i],
            )
            p.circle(
                "deciles",
                lines[i],
                source=src,
                fill_color=colors[i],
                legend_label=labels[i],
                line_color=None,
                name=labels[i],
            )
        p.xaxis.tags = ["numeric"]

        plot = plotstyle(p, plot_dict)

        # Table to display source data

        columns = [
            TableColumn(field="deciles", title="Deciles"),
            TableColumn(field="total_income", title="Total income (before tax)"),
            TableColumn(field="labor_income", title="Labor income (before tax)"),
            TableColumn(field="capital_income", title="Capital income (before tax)"),
            TableColumn(field="net_income", title="Total income (after tax)"),
            TableColumn(field="weights", title="Decile weights"),
        ]

        data_table = DataTable(
            source=src_raw,
            columns=columns,
            width=800,
            height=350,
            selectable=False,
            autosize_mode="fit_columns",
        )

        return plot, data_table
예제 #5
0
    def setup_plot(src_heatmap):

        colors = Turbo256[80:220]
        colors = list(colors)
        colors.reverse()

        mapper = LinearColorMapper(
            palette=colors,
            low=min(src_heatmap.data["total"]),
            high=max(src_heatmap.data["total"]),
        )

        # Actual figure setup
        p = figure(
            plot_width=800,
            plot_height=400,
            x_range=(0, 1),
            y_range=(0, 2),
            tools="save",
        )

        p.rect(
            x="Recovered_portion",
            y="Elasticity",
            width=0.05,
            height=0.01,
            source=src_heatmap,
            line_color=None,
            fill_color=transform("total", mapper),
        )

        booleans = [
            True if total > -0.5 and total < 0.5 else False
            for total in src_heatmap.data["total"]
        ]
        view = CDSView(source=src_heatmap, filters=[BooleanFilter(booleans)])
        p.circle(
            x="Recovered_portion",
            y="Elasticity",
            source=src_heatmap,
            view=view,
            fill_color="black",
            line_color=None,
            name="circle",
        )

        color_bar = ColorBar(
            color_mapper=mapper,
            location=(0, 0),
            ticker=BasicTicker(desired_num_ticks=20),
            formatter=NumeralTickFormatter(format="0€"),
            label_standoff=12,
            title="Reform revenue effect (in Mio. €)",
        )
        p.add_layout(color_bar, "right")

        p.xaxis.tags = ["numeric"]

        plot = plotstyle(p, plot_dict)

        return plot
예제 #6
0
    def make_plot(src):
        p = figure(
            plot_width=800,
            plot_height=400,
            y_range=src.data["deciles"],
            tooltips="@deciles: @delta_tax_burden{0€} Mio.€",
        )

        labels = LabelSet(
            x="delta_tax_burden",
            y="deciles",
            text="label",
            source=src,
            x_offset="offset",
            y_offset=-10,
            render_mode="canvas",
        )

        color_mapper = LinearColorMapper(
            palette=RdYlGn[10],
            low=max(src.data["delta_tax_burden"]) - 120,
            high=min(src.data["delta_tax_burden"]),
        )

        p.hbar(
            y="deciles",
            right="delta_tax_burden",
            source=src,
            height=0.8,
            color={
                "field": "delta_tax_burden",
                "transform": color_mapper
            },
            line_color=None,
        )

        # Table to display source data
        columns = [
            TableColumn(field="deciles", title="Deciles"),
            TableColumn(field="delta_tax_burden",
                        title="Tax revenue change (in Million €)"),
            TableColumn(
                field="Delta_ETR",
                title="Effective tax rate change (ΔETR)",
                formatter=NumberFormatter(format="0.0000%"),
            ),
        ]

        data_table = DataTable(source=src,
                               columns=columns,
                               width=800,
                               height=350)

        p.add_layout(labels)

        p.xaxis.tags = ["numeric"]
        p.yaxis.tags = ["categorical"]

        plot = plotstyle(p, plot_dict)

        return plot, data_table