我试图在Dash中显示多个不同的饼图。虽然这本身并不难,但为它们分配标题似乎非常困难。请考虑以下代码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')
为了给每个甜甜圈一个标题,有必要使用注释并为每个单独的图形坐标 。虽然这对于两个圆环图来说是可行的,但对于10到20个它们来说肯定会变得非常繁重。此外,一旦你设法得到正确的坐标,使得标题非常适合图形,你可以重复整个过程,如果你想改变标题(因为标题长度不同)。
我的问题:有没有更快捷的方法将标题分配给饼图,然后在前面提到的教程中提出?
我尝试过以下方法:
dcc.Graph
元素。这似乎没有给出好的结果。plotly.tools
。遗憾的是tools
无法使用饼图。