From 1530587291561bd2db4617cd3adabb247e0b7cdb Mon Sep 17 00:00:00 2001 From: Ben Welsh Date: Mon, 20 Oct 2025 00:00:33 +0000 Subject: [PATCH] Update ColumnChart example with improved annotations and data source --- docs/user-guide/charts/column-charts.md | 59 +++++++++++++++++-------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/docs/user-guide/charts/column-charts.md b/docs/user-guide/charts/column-charts.md index 9475d63..83609c9 100644 --- a/docs/user-guide/charts/column-charts.md +++ b/docs/user-guide/charts/column-charts.md @@ -1,15 +1,15 @@ # ColumnChart -## Example +This example, drawn from the Datawrapper documentation, demonstrates how to customize a column chart with annotations and custom colors. -This example demonstrates how to create a column chart showing U.S. unemployment rates from 2016-2020, highlighting the dramatic spike during the COVID-19 pandemic. + ```python import pandas as pd import datawrapper as dw # Load unemployment data from GitHub -url = "https://raw.githubusercontent.com/palewire/datawrapper-api-classes/main/tests/samples/column/unemployment.csv" +url = "https://raw.githubusercontent.com/chekos/datawrapper/main/tests/samples/column/unemployment.csv" df = pd.read_csv(url) chart = dw.ColumnChart( @@ -19,30 +19,53 @@ chart = dw.ColumnChart( source_name="U.S. Bureau of Labor Statistics", source_url="https://www.bls.gov/", # Introductory text - intro="Seasonally adjusted unemployment rate, January 2016 - September 2020", - # Chart byline - byline="Sergio Hernandez", + intro="January 2016-September 2020", # Data from pandas DataFrame data=df, - # Format Y-axis grid labels with one decimal place - y_grid_format=dw.NumberFormat.ONE_DECIMAL, - # Always show value labels - show_value_labels="always", - # Place value labels outside the columns - value_labels_placement="outside", + # Format Y-axis grid labels with one decimal place and a percentage sign + y_grid_format=dw.NumberFormat.PERCENT_UP_TO_ONE_DECIMAL, # Format value labels with one decimal place - value_labels_format=dw.NumberFormat.ONE_DECIMAL, - # Set fixed plot height in pixels - plot_height=228, + value_labels_format=dw.NumberFormat.PERCENT_UP_TO_ONE_DECIMAL, # Highlight specific column in red - column_color={"2020/04": "#c71e1d"}, + base_color="#CCCCCC", + color_category={ + "2020/04": "rgb(21, 96, 122)", + "2020/05": "rgb(21, 96, 122)", + "2020/06": "rgb(21, 96, 122)", + "2020/07": "rgb(21, 96, 122)", + "2020/08": "rgb(21, 96, 122)", + "2020/09": "rgb(21, 96, 122)", + }, + range_annotations=[ + dw.RangeAnnotation( + x0="2020/01/01", + x1="2020/09/30", + color="#777777", + opacity=10, + type="x", + ) + ], + text_annotations=[ + dw.TextAnnotation( + x="2020/04/01", + y=14, + dx=-50, + dy=50, + text="In April 2020, the unemployment rate rose to almost 15%.", + align="tr", + size=14, + color="rgb(21, 96, 122)", + connector_line=dw.ConnectorLine( + color="rgb(21, 96, 122)", + type=dw.ConnectorLineType.CURVE_RIGHT, + ), + ) + ], ) chart.create() ``` -
- ## Reference ```{eval-rst}