• AIPressRoom
  • Posts
  • Three Charts to Signify a Proportion You Might Not Know | by Angelica Lo Duca | Aug, 2023

Three Charts to Signify a Proportion You Might Not Know | by Angelica Lo Duca | Aug, 2023

Knowledge Visualization, Python

A ready-to-run tutorial in Python Altair to construct charts to symbolize a proportion

Representing a proportion visually could interact the viewers extra and assist them higher perceive the information. There are alternative ways to symbolize a proportion visually. Essentially the most simple technique is a Large Quantity (BAN), as proven within the determine under.

Along with BAN, there are different methods to symbolize a proportion visually. On this article, we’ll deal with three methods:

  • Donut Chart

  • 100% Stacked Chart

  • Waffle Chart.

We’ll use Python Altair to point out the best way to construct every technique. The Vega-Altair library (Altair, for brief) is a declarative Python library for statistical visualization primarily based on the Vega and Vega-Lite visualization grammars. For extra particulars on the best way to get began with Altair, you may learn the official Python Altair documentation.

To indicate how every sort of chart works, we’ll symbolize the next proportion: 70%. To symbolize this worth, it’s essential to use the next Pandas DataFrame:

knowledge = {
'proportion': [0.7,0.3],
'label' : ['70%','30%'],
'coloration' : ['#81c01e','lightgray']
}

df = pd.DataFrame(knowledge)

The DataFrame should comprise two values: the share (70%) and its complementary worth (30%). As well as, we set the colours related to every slice: #81c01e (a kind of inexperienced) for our worth, and lightweight grey for the opposite.

Let’s begin representing this DataFrame by a donut chart.

A donut chart is a round chart displaying knowledge in a hoop form. It’s just like the pie chart however with a gap within the middle, creating a visible illustration of percentages of various classes.