ArrowChart

This example, drawn from the Datawrapper documentation, demonstrates how to create an arrow chart with customized sorting and highlighted elements.

import pandas as pd
import datawrapper as dw

# Load data from GitHub
url = "https://raw.githubusercontent.com/chekos/datawrapper/main/tests/samples/arrow/inequality.csv"
df = pd.read_csv(url, sep="\t")

# Create arrow chart
chart = dw.ArrowChart(
    # Chart title
    title="Many European countries bring income inequality down with taxes. The US and Mexico: Not so much.",
    # The description line with a bit of HTML
    intro="Income inequality (gini index) in selected OECD countries in 2014, before and after taxes. A gini index of 0 means that every household earns exactly the same income, while an index of 1 means that one household in the country makes all the income. <b>The lower the Gini index, the more equal the income is distributed in a country.</b>",
    # Data source attribution
    source_name="OECD",
    # The byline
    byline="Lisa Charlotte Rost, Datawrapper",
    # Pass the DataFrame
    data=df,
    # Start column (Gini before taxes)
    start_column="Gini before taxes",
    # End column (Gini after taxes)
    end_column="Gini after taxes",
    # Custom X-axis range
    range_extent="custom",
    custom_range=[0.15, 0.6],
    # Value label format (three decimal places)
    value_label_format=dw.NumberFormat.THREE_DECIMALS,
    # Sort by the start column
    sort_by="end",
    # Enable sorting
    sort_ranges=True,
    # Show arrow key/legend
    arrow_key=True,
    # Set the default arrow color
    base_color="rgb(196, 148, 67)",
    # Highlight specific countries in red
    color_column="Country",
    label_column="Country",
    color_category={
        "<b>Mexico</b>": "#c71e1d",
        "<b>United States</b>": "#c71e1d"
    }
)

# Create the chart in Datawrapper
chart.create()

Reference

Parameter

Default

Description

Type

aria_description

“”

The alternative text for screen readers

str

arrow_key

False

Label on the first arrow that shows column names

bool

auto_dark_mode

False

Whether the chart should automatically flip to dark mode when the user’s system is in dark mode

bool

base_color

0

The base color for the arrows

str or int

byline

“”

The byline that appears below the chart

str

chart_id

None

The chart ID after creation (populated by create() method)

str or None

chart_type

“d3-arrow-plot”

The type of datawrapper chart to create

Literal[d3-arrow-plot]

color_category

PydanticUndefined

A mapping of layer names to colors

dict[str, str]

color_column

None

The column to color by

str or None

custom

PydanticUndefined

A dictionary of custom tags to attach to the chart

dict[str, Any]

custom_range

PydanticUndefined

The custom range for the x axis

list[Any] or tuple[Any, Any]

dark_mode_invert

True

Whether to invert colors in dark mode

bool

data

PydanticUndefined

The data to use for the chart

DataFrame or list[dict]

download_image

False

Whether to allow PNG download

bool

download_pdf

False

Whether to allow PDF download

bool

download_svg

False

Whether to allow SVG download

bool

embed

False

Whether to allow embedding

bool

end_column

None

The column that arrows should end at

str or None

force_attribution

False

Whether to attribute the chart to datawrapper

bool

forkable

True

Whether to allow other users to fork this visualization

bool

get_the_data

False

Whether to allow data downloads

bool

groups_column

None

The column to group arrows by

str or None

hide_title

False

Whether or not to hide the title

bool

intro

“”

The intro text that appears above the chart

str

label_column

None

The column to label by

str or None

language

“en-US”

The locale of the chart, which defines decimal and thousand separators as well as translations of month and weekday names.

str

logo

False

Whether to show a logo

bool

logo_id

“”

The id of the logo to show

str

notes

“”

The footnotes that appear below the chart

str

range_extent

“nice”

The type of range on the x-axis

Literal[nice, custom, data]

range_value_labels

“”

The field you want to use for the value labels

str

replace_flags

“off”

Whether to replace country codes with flags. Use ReplaceFlagsType enum for type safety or provide raw strings.

ReplaceFlagsType (OFF, FOUR_BY_THREE, ONE_BY_ONE, …) or str

reverse_order

False

Reverse the order of the ranges

bool

share_buttons

False

Whether to show social media share buttons

bool

share_url

“”

What URL to share

str

sort_by

“end”

How to sort the ranges

Literal[end, start, difference, change]

sort_ranges

False

Whether to sort the ranges

bool

source_name

“”

The source name that appears below the chart

str

source_url

“”

The source URL that appears below the chart

str

start_column

None

The column that arrows should start at

str or None

theme

“datawrapper”

The theme of the chart

str

thick_arrows

True

Thicken the arrows

bool

title

“”

The headline that appears above the chart

str

transformations

PydanticUndefined

Transform or dict[str, Any]

value_label_format

“”

The number format for value labels. Use DateFormat for temporal data, NumberFormat for numeric data, or provide custom format strings.

DateFormat (AUTO, YEAR_FULL, YEAR_TWO_DIGIT, …) or NumberFormat (AUTO, THOUSANDS_WITH_OPTIONAL_DECIMALS, INTEGER, …) or str

y_grid

“on”

Show the y-axis grid lines

str