I’m trying to display multiple different pie charts in Dash. While this in itself is not that hard to do, assigning titles to them appears to be very hard. Please consider the following code from this tutorial:
fig = {
"data": [
{
"values": [16, 15, 12, 6, 5, 4, 42],
"labels": [
"US",
"China",
"European Union",
"Russian Federation",
"Brazil",
"India",
"Rest of World"
],
"domain": {"x": [0, .48]},
"name": "GHG Emissions",
"hoverinfo":"label+percent+name",
"hole": .4,
"type": "pie"
},
{
"values": [27, 11, 25, 8, 1, 3, 25],
"labels": [
"US",
"China",
"European Union",
"Russian Federation",
"Brazil",
"India",
"Rest of World"
],
"text":"CO2",
"textposition":"inside",
"domain": {"x": [.52, 1]},
"name": "CO2 Emissions",
"hoverinfo":"label+percent+name",
"hole": .4,
"type": "pie"
}],
"layout": {
"title":"Global Emissions 1990-2011",
"annotations": [
{
"font": {
"size": 20
},
"showarrow": False,
"text": "GHG",
"x": 0.20,
"y": 0.5
},
{
"font": {
"size": 20
},
"showarrow": False,
"text": "CO2",
"x": 0.8,
"y": 0.5
}
]
}
}
py.iplot(fig, filename='donut')
In order to give each donut a title, it is necessary to use annotations and coordinates for every separate graph. While this is doable for two donut graphs, it certainly becomes an awful lot of work for 10 - 20 of them. Furthermore, once you have managed to get the coordinates right so that the titles fit nicely above the graphs, you can repeat the whole process if you want to change the titles (because of different title lengths).
My Question: Is there a quicker way to assign titles to pie-charts then suggested in the tutorial mentioned earlier?
I’ve tried the following approaches:
- Create 10 different
dcc.Graph
elements in my app. This doesn’t seem to give nice results. - Use
plotly.tools
. Unfortunatelytools
doesn’t work with pie-charts.