Two-Dimensional Dictionary in Pie Chart

Hi! I am trying to make a two-dimensional pie plot with Bokeh and Pandas.
I have been following Bokeh’s documentation on creating a regular pie chart, which works great. I want to expand on the example found in the documentation by segmenting the different countries in their respective continent, like so:

x = {
    "Africa": {
        "Egypt": 157,
        "Kenya": 35,
        "Morocco": 32,
        "Nigeria": 93
    },
    "Asia": {
        "China": 63,
        "India": 42,
        "Japan": 89,
        "Taiwan": 31
    },
    "Europe": {
        "France": 31,
        "Germany": 44,
        "Italy": 40,
        "Spain": 29
    }
}

I want a pie plot where there is an inner diagram for the continents and sub-segments on the outside representing the individual countries.

I’ve tried making DataFrames in Pandas with the original example, aswell as with my own data set, but I’m starting to believe that I need to create different pie charts that I overlay with one another to get the results I’m wanting as nested dictionaries or lists don’t yield proper DataFrames.

import pandas

# The data we have to work with.
x = {
    'United States': 157,
    'United Kingdom': 93,
    'Japan': 89,
    'China': 63,
    'Germany': 44,
    'India': 42,
    'Italy': 40,
    'Australia': 35,
    'Brazil': 32,
    'France': 31,
    'Taiwan': 31,
    'Spain': 29,
}

# Building the DataFrame using Pandas.
data = pandas.Series(x).reset_index(name = 'value').rename(columns = { 'index': 'country' })

print(data)

Will yield:

country value
United States 157
United Kingdom 93
Japan 89
China 63
Germany 44
India 42
Italy 40
Australia 35
Brazil 32
France 31
Taiwan 31
Spain 29

If I replace the data set with my custom dictionary, I instead get:

country value
Africa {‘Egypt’: 157, ‘Kenya’: 35, ‘Morocco’: 32, 'Ni…
Asia {‘China’: 63, ‘India’: 42, ‘Japan’: 89, 'Taiwa…
Europe {‘France’: 31, ‘Germany’: 44, ‘Italy’: 40, 'Sp…

Any help would be greatly appreciated.

In order to do this, you will need to construct a pie chart with wedge glyphs for the inner part, and a donut chart with annular wedge glyphs for the outer part. There used to be an example of this in the repo, but it was removed since it was a bit more complicated than we like our example code to be. However you can still see the code by navigating to the old release tag:

bokeh/examples/models/file/donut.py at 2.4.3 · bokeh/bokeh · GitHub

I just just checked that this code still runs as-is with latest Bokeh 3.6.2 and generates the output below. Note that this code uses the lower level bokeh.models API directly. I don’t have anything similar to share that uses bokeh.plotting instead. Still, hopefully this is a useful reference.