Three Charts to Represent a Percentage You May Not Know | by Angelica Lo Duca | Aug, 2023

,

A ready-to-run in Python Altair to charts to represent a percentage

Angelica Lo Duca
Towards Data Science
Photo by Markus Winkler on Unsplash

Representing a percentage visually may engage the audience more and help them better understand the . There are different ways to represent a percentage visually. The most straightforward is a Big Number (BAN), as shown in the below.

by Author

In addition to BAN, there are other ways to represent a percentage visually. In this article, we will focus on three strategies:

  • Donut Chart
  • 100% Stacked Chart
  • Waffle Chart.

We will use Python Altair to show how to build each strategy. The Vega-Altair library (Altair, for short) is a declarative Python library for statistical visualization based on the Vega and Vega-Lite visualization grammars. For more details on how to get started with Altair, you can read the official Python Altair documentation.

To show how each type of chart works, we will represent the following percentage: 70%. To represent this value, you must use the following DataFrame:

data = {
'percentage': [0.7,0.3],
'label' : ['70%','30%'],
'color' : ['#81c01e','lightgray']
}

df = pd.DataFrame(data)

The DataFrame must contain two values: the percentage (70%) and its complementary value (30%). In addition, we set the associated with each slice: #81c01e (a type of green) for our value, and light gray for the other.

Let’s start representing this DataFrame through a donut chart.

A donut chart is a circular chart displaying data in a ring shape. It is similar to the pie chart but with a hole in the center, creating a visual representation of percentages of different categories.

Source link