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.