appendix C Other chart types

 

This appendix describes some of the most popular charts not covered in chapter 6. Use it as a reference if you want to try new charts. The code for the charts is described in the book’s GitHub repository, under 06, in addition to other, less popular charts. Let’s investigate each chart type separately, starting with the cooking chart family.

C.1 Donut chart

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

To convert a pie chart into a donut chart, simply add the innerRadius and outerRadius properties to the mark_arc() method, as shown in the following listing.

Listing C.1 The code to generate a donut chart
import pandas as pd
import altair as alt

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

df = pd.DataFrame(data)

chart = alt.Chart(df).mark_arc(
    innerRadius=100,
    outerRadius=150
).encode( 
    theta='percentage',
    color=alt.Color('color', scale=None),
    tooltip='label'
).properties(
    width=300,
    height=300
)

C.2 Bar charts family

C.2.1 Column chart

C.2.2 Column chart with multiple series

C.2.3 Pyramid chart

C.2.4 Stacked column chart

C.2.5 100% stacked column chart

C.2.6 Histograms

C.3 Line charts family

C.3.1 Area chart

C.3.2 Slope chart

C.3.3 Dumbbell chart