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 |
|---|---|---|---|
|
“” |
The alternative text for screen readers |
str |
|
False |
Label on the first arrow that shows column names |
bool |
|
False |
Whether the chart should automatically flip to dark mode when the user’s system is in dark mode |
bool |
|
0 |
The base color for the arrows |
str or int |
|
“” |
The byline that appears below the chart |
str |
|
None |
The chart ID after creation (populated by create() method) |
str or None |
|
“d3-arrow-plot” |
The type of datawrapper chart to create |
Literal[d3-arrow-plot] |
|
PydanticUndefined |
A mapping of layer names to colors |
dict[str, str] |
|
None |
The column to color by |
str or None |
|
PydanticUndefined |
A dictionary of custom tags to attach to the chart |
dict[str, Any] |
|
PydanticUndefined |
The custom range for the x axis |
list[Any] or tuple[Any, Any] |
|
True |
Whether to invert colors in dark mode |
bool |
|
PydanticUndefined |
The data to use for the chart |
DataFrame or list[dict] |
|
False |
Whether to allow PNG download |
bool |
|
False |
Whether to allow PDF download |
bool |
|
False |
Whether to allow SVG download |
bool |
|
False |
Whether to allow embedding |
bool |
|
None |
The column that arrows should end at |
str or None |
|
False |
Whether to attribute the chart to datawrapper |
bool |
|
True |
Whether to allow other users to fork this visualization |
bool |
|
False |
Whether to allow data downloads |
bool |
|
None |
The column to group arrows by |
str or None |
|
False |
Whether or not to hide the title |
bool |
|
“” |
The intro text that appears above the chart |
str |
|
None |
The column to label by |
str or None |
|
“en-US” |
The locale of the chart, which defines decimal and thousand separators as well as translations of month and weekday names. |
str |
|
False |
Whether to show a logo |
bool |
|
“” |
The id of the logo to show |
str |
|
“” |
The footnotes that appear below the chart |
str |
|
“nice” |
The type of range on the x-axis |
Literal[nice, custom, data] |
|
“” |
The field you want to use for the value labels |
str |
|
“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 |
|
False |
Reverse the order of the ranges |
bool |
|
False |
Whether to show social media share buttons |
bool |
|
“” |
What URL to share |
str |
|
“end” |
How to sort the ranges |
Literal[end, start, difference, change] |
|
False |
Whether to sort the ranges |
bool |
|
“” |
The source name that appears below the chart |
str |
|
“” |
The source URL that appears below the chart |
str |
|
None |
The column that arrows should start at |
str or None |
|
“datawrapper” |
The theme of the chart |
str |
|
True |
Thicken the arrows |
bool |
|
“” |
The headline that appears above the chart |
str |
|
PydanticUndefined |
Transform or dict[str, Any] |
|
|
“” |
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 |
|
“on” |
Show the y-axis grid lines |
str |