diff --git a/docs/user-guide/charts/multiple-column-charts.md b/docs/user-guide/charts/multiple-column-charts.md index 7a35b6c..25445b7 100644 --- a/docs/user-guide/charts/multiple-column-charts.md +++ b/docs/user-guide/charts/multiple-column-charts.md @@ -1,5 +1,86 @@ # MultipleColumnChart +This example, drawn from [Datawrapper's official documentation](https://www.datawrapper.de/charts/multiple-columns), demonstrates how to create small multiple column charts showing population growth in major cities from 1950 to 2035. The chart features custom panel titles with country information, highlighted data for 2025, a range annotation to mark the projection period and a 4-column grid layout. + + + +```python +import pandas as pd +import datawrapper as dw + +# Load population data from GitHub +df = pd.read_csv( + "https://raw.githubusercontent.com/chekos/Datawrapper/main/tests/samples/multiple_column/population.csv", + sep="\t" +) + +chart = dw.MultipleColumnChart( + # Chart title + title="Population of the world's largest cities, 1950 to 2035", + # Data source attribution + source_name="Our World in Data", + source_url="https://ourworldindata.org/urbanization", + # Data from pandas DataFrame + data=df, + # Layout configuration - 4 columns on desktop, 2 on mobile + grid_layout="fixedCount", + grid_column=4, + grid_column_mobile=2, + grid_row_height=140, + # Sort panels by end value (2035 population) in descending order + sort=True, + sort_by="end", + sort_reverse=False, + # Set custom column color with highlighted year for 2025 + base_color="#c9a291", + color_category={ + "2025": "#c71e1d" + }, + # Format y-axis with abbreviated numbers + y_grid_format=dw.NumberFormat.ABBREVIATED_ONE_DECIMAL, + y_grid_labels="inside", + y_grid_label_align="left", + # Custom panel titles with city and country information + panels=[ + {"column": "Delhi", "title": "Delhi, India"}, + {"column": "Dhaka", "title": "Dhaka, Bangladesh "}, + {"column": "Lagos", "title": "Lagos, Nigeria"}, + {"column": "Paris", "title": "Paris, France"}, + {"column": "Tokyo", "title": "Tokyo, Japan"}, + {"column": "Beijing", "title": "Beijing, China"}, + {"column": "Mumbai (Bombay)", "title": "Mumbai, India"}, + {"column": "New York-Newark", "title": "New York/Newark, U.S."}, + ], + # Add text annotation to label the projection period + text_annotations=[ + { + "text": "2025", + "x": "2023/01/01", + "y": 30000000, + "align": "tc", + "color": "#b73229", + "size": 14, + "bold": True, + }, + ], + # Add range annotation to highlight projection period + range_annotations=[ + { + "x0": "2018/01/01", + "x1": "2037/07/02", + "y0": 0, + "y1": 50000000, + "display": "range", + "color": "#888", + "opacity": 18, + }, + ], +) + +# Create the chart in Datawrapper +chart.create() +``` + ## Reference ```{eval-rst} diff --git a/docs/user-guide/charts/scatter-plots.md b/docs/user-guide/charts/scatter-plots.md index 8a9e3da..dc19258 100644 --- a/docs/user-guide/charts/scatter-plots.md +++ b/docs/user-guide/charts/scatter-plots.md @@ -1,5 +1,130 @@ # ScatterPlot +This example, drawn from [Datawrapper's official documentation](https://www.datawrapper.de/charts/scatter-plot), demonstrates how to create a scatter plot showing the relationship between GDP per capita and life expectancy over time. The chart uses bubble size to represent population and features text annotations to label specific countries and years. + + + +```python +import pandas as pd +import datawrapper as dw + +# Load life expectancy data from GitHub +df = pd.read_csv( + "https://raw.githubusercontent.com/chekos/Datawrapper/main/tests/samples/scatter/life-expectancy.csv", + sep="\t" +) + +chart = dw.ScatterPlot( + # Chart title + title="Every country has a higher life expectancy now than in 1800", + # Introductory text explaining the visualization + intro="Gross domestic product per person adjusted for differences in purchasing power (in international 2011 dollars) vs life expectacy of newborns, for selected countries in 1800 and 2015. The size of the circle shows the population of the countries.", + # Data source attribution + source_name="Gapminder", + source_url="https://www.gapminder.org/data/", + # Author credit + byline="Lisa Charlotte Muth, Datawrapper", + # Data from pandas DataFrame + data=df, + # Define which columns to use for each dimension + x_column="GPD", + y_column="Health", + size_column="population", + label_column="country", + # Use logarithmic scale for x-axis (GDP) + x_log=True, + # Set custom range for axes + x_range=[200, ""], + y_range=[0, 94], + # Format axis labels + x_format="0a", # Abbreviated format (e.g., "10k") + y_format="0a", + # Configure bubble size + size="dynamic", + max_size=60, + # Set opacity for better visibility of overlapping bubbles + opacity=0.6, + # Set base color for all points + base_color="#15607a", + # Set fixed plot height + plot_height_fixed=581, + # Disable automatic labeling (we'll add custom text annotations) + auto_labels=False, + # Custom tooltip format + tooltip_title='{{ country }} in {{ FORMAT(year, "YYYY") }}', + tooltip_body="""
| Life expectancy: | +GDP per capita: | +
| {{ health }} years | +{{ FORMAT(gdp, "0,0") }} Int'l$ | +