Skip to main content

A python package to produce charts following UK Government Analysis Function guidance

Project description

afcharts-py afcharts logo

Overview

The afcharts python package helps make accessible Matplotlib and Plotly charts following Government Analysis Function Data Visualisation guidance:

  • Automatic chart formatting with pre-built style sheets for Matplotlib and Plotly
  • Chart colours from the Analysis Function accessible colour palettes
  • Example code for common chart types in the cookbook

Looking for the R version? Check out the afcharts R package.

A grouped bar chart in afcharts style showing life expectancy in 1967 and 2007 for four countries. Bars use Analysis Function palette: dark blue for 1967, orange for 2007. A scatterplot in afcharts style showing life expectancy against GDP per capita for 142 countries in 2007. A line chart in afcharts style showing life expectancy in China and the UK from 1952 to 2007

Installation

afcharts is available at the Python Package Index (PyPI):

pip install afcharts

or see the alternative installation instructions.

Usage

Format any Matplotlib or Plotly chart in the Analysis Function style using the built-in style sheets.

See the Getting Started guide for more options and the cookbook for extensive examples.

Matplotlib

import matplotlib.pyplot as plt

# Apply the afcharts style to all Matplotlib plots
plt.style.use('afcharts.afcharts')

Example: A Matplotlib bar chart with afcharts (left) and without (right)

Grouped bar chart (afcharts style) showing life expectancy in 1967 and 2007 for four countries. Bars use Analysis Function palette: dark blue for 1967, orange for 2007. Grouped bar chart (default Matplotlib) showing life expectancy in 1967 and 2007 for four countries. Bars: blue for 1967, orange for 2007.

Plotly

from afcharts.pio_template import pio

# Apply the afcharts style to all Plotly plots
pio.templates.default = "afcharts"

Example: A Plotly bar chart with afcharts (left) and without (right)

Grouped bar chart (afcharts style) showing life expectancy in 1967 and 2007 for four countries. Bars use Analysis Function palette: dark blue for 1967, orange for 2007. Grouped bar chart (default Plotly) showing life expectancy in 1967 and 2007 for four countries. Bars: blue for 1967, red for 2007.

Colours

Easily return a list of colours from any of the Analysis Function accessible colour palettes with the get_af_colours() function:

from afcharts.af_colours import get_af_colours

# Get the duo colour palette hex codes
duo = get_af_colours("duo")

Getting help

If you encounter a bug, please file a minimal reproducible example on Github Issues. For questions and other discussion, please start a discussion.

Contributing

Interested in contributing? Check out the contributing guidelines.

Acknowledgments

The afcharts python package is based on the afcharts R package and the py-af-colours package.

License

Unless stated otherwise, the codebase is released under the MIT License. This covers both the codebase and any sample code in the documentation.

The documentation is © Crown copyright and available under the terms of the Open Government 3.0 licence.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afcharts-1.1.2.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

afcharts-1.1.2-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file afcharts-1.1.2.tar.gz.

File metadata

  • Download URL: afcharts-1.1.2.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for afcharts-1.1.2.tar.gz
Algorithm Hash digest
SHA256 85b686856aa55c538b8b245f361ddbf99789c5a90d03217399a1d6f71411bf41
MD5 4d92924f2c54df0d1aa4b562d5879faf
BLAKE2b-256 f1213317d816c0988b261b131fa837e0024b5264cbda757f2e937a6ad154af89

See more details on using hashes here.

Provenance

The following attestation bundles were made for afcharts-1.1.2.tar.gz:

Publisher: publish.yml on best-practice-and-impact/afcharts-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file afcharts-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: afcharts-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for afcharts-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb6a139528d3f67db5064c0949fd61340d311e768f7f7cc90071d3ec5321484e
MD5 2fc04029cd30f15ec6ddf6f0c2f6c72a
BLAKE2b-256 2b405cb3842f66f5b9166733ab29ceb6b4fbdae8d2d681418cf80a35d5c314c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for afcharts-1.1.2-py3-none-any.whl:

Publisher: publish.yml on best-practice-and-impact/afcharts-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page