def _bar_stacked_example_4()

in chartify/examples.py [0:0]


def _bar_stacked_example_4(quantity_by_fruit_and_country, country_order):
    """Docstring"""
    # Add a column for labels.
    # Note: Null labels will not be added to the chart.
    quantity_by_fruit_and_country["label"] = np.where(
        quantity_by_fruit_and_country["country"].isin(["US", "CA"]),
        quantity_by_fruit_and_country["quantity"],
        None,
    )

    (
        chartify.Chart(blank_labels=True, x_axis_type="categorical")
        .set_title("Stacked bar with labels")
        .set_subtitle("")
        .plot.bar_stacked(
            data_frame=quantity_by_fruit_and_country,
            categorical_columns=["fruit"],
            numeric_column="quantity",
            stack_column="country",
            normalize=True,
            stack_order=country_order,
        )
        .plot.text_stacked(
            data_frame=quantity_by_fruit_and_country,
            categorical_columns=["fruit"],
            numeric_column="quantity",
            stack_column="country",
            text_column="label",
            normalize=True,
            stack_order=country_order,
            # Set the text color otherwise it will take
            # The next color in the color palette.
            text_color="white",
        )
        .show(_OUTPUT_FORMAT)
    )