4  Government Analysis Function colour palettes

The afcharts python package provides easy access to the Government Analysis Function accessible colour palettes.

UK legislation requires that content on public sector websites must meet Web Content Accessibility Guidelines (WCAG) 2.2. The Government Analysis Function palettes have been designed to meet these criteria by maximising colour contrast with a white background, as well as with adjacent colours in the palette.

4.1 Using afcharts colour palettes

4.1.1 Basic usage

Import get_af_colours() with:

from afcharts.af_colours import get_af_colours

Call get_af_colours() with the name of the colour palette as the first argument: “duo”, “focus”, “sequential” or “categorical”. For example, to return the duo colour palette:

get_af_colours("duo")
# ['#12436D', '#F46A25']

4.1.2 Number of colours

By default, get_af_colours() will return all colours in the given palette. For the categorical palette, the number of colours returned can be set with the number_of_colours argument.

For example, to return four colours from the categorical palette as hex codes:

get_af_colours("categorical", number_of_colours=4)
# ['#12436D', '#28A197', '#801650', '#F46A25']

4.1.3 RGB colour codes

By default, get_af_colours() will return a list of hexadecimal colour codes. To return RGB colour codes instead, set colour_format="rgb".

For example, to return the sequential colour palette as a list of rgb code tuplets:

get_af_colours("sequential", colour_format="rgb")                      
# [(18, 67, 109), (32, 115, 188), (107, 172, 230)]

4.2 Available colour palettes

4.2.1 Categorical palette

The categorical palette is for data which can be divided into groups or categories using names or labels.

Hex Code Preview
#12436D
#28A197
#801650
#F46A25
#3D3D3D
#A285D1


Note: It is best practice to limit charts to a maximum of four categories where possible to avoid clutter.

4.2.2 Duo palette

The duo palette should be used if only two colours are required. It contains the two colours from the categorical palette with the highest contrast ratio.

Hex Code Preview
#12436D
#F46A25

4.2.3 Sequential palette

The sequential colour palette should be used for data where the order has some meaning, such as age groups.

Hex Code Preview
#12436D
#2073BC
#6BACE6

4.2.4 Focus palette

The focus palette should be used to highlight specific elements of a plot to help users better understand the information.

Hex Code Preview
#12436D
#BFBFBF


Note: The light grey colour in this palette does not have sufficient colour contrast against a white background and therefore this palette should only be used when it is essential to communicate your message. Follow the advice for using the focus palette in the Government Analysis Function colour guidance when using this palette.

4.3 Things to consider when using colour

Using the afcharts colour palettes does not guarantee that your charts will be accessible. Use these palettes in conjunction with Government Analysis Function advice on what to consider when using colour in charts.

The following are a few key things to consider when using colour in data visualisations:

  • Only use colour if absolutely necessary
  • Do not rely on colour alone to communicate a message
  • Use colour consistently when producing a series of plots
  • Limit the number of different colours you use; ideally an absolute maximum of four
  • Use colour palettes in the order presented to ensure adjacent colours have sufficient contrast with each other

4.4 Using your own colour palette

There may be instances where you’d like to use a different colour palette. If so, this should be carefully considered to ensure it meets accessibility requirements. The Government Analysis Function guidance outlines appropriate steps for choosing your own accessible colour palette that should be used.