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 )
Note The code to generate a donut chart in Altair. Use the innerRadius
and outerRadius
to transform a pie chart into a donut chart.