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.
afcharts is available at the Python Package Index (PyPI):
pip install afchartsor see the alternative installation instructions.
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.
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)
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)
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")If you encounter a bug, please file a minimal reproducible example on Github Issues. For questions and other discussion, please start a discussion.
Interested in contributing? Check out the contributing guidelines.
The afcharts python package is based on the afcharts R package and the py-af-colours package.
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.





