在pygal中合并并比较两组堆叠数据

Combine and compare two sets of stacked data in pygal

我想知道是否可以将两组数据(分别由两个列表组成)合并到一个 pygal 图表中。

代码看起来像这样:

new_chart = pygal.StackedBar()

# set 1
new_chart.add('1-1',[1,2,3,4])
new_chart.add('1-2',[4,3,2,1])

# set 2
new_chart.add('2-1',[9,8,7,6])
new_chart.add('2-2',[6,7,8,9])

new_chart.render()

但我希望第二组紧挨着第一组(而不是堆叠在第一组之上)。

这样就可以了:

new_chart = pygal.StackedBar()

# set 1
new_chart.add('1-1',[1, 0, 2, 0, 3, 0, 4, 0])
new_chart.add('1-2',[4, 0, 3, 0, 2, 0, 1, 0])

# set 2
new_chart.add('2-1',[0, 9, 0, 8, 0, 7, 0, 6])
new_chart.add('2-2',[0, 6, 0, 7, 0, 8, 0, 9])

您可以获得更清晰的图像,并为空白区域添加零:

new_chart = pygal.StackedBar()
# set 1
new_chart.add('1-1',[1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0])
new_chart.add('1-2',[4, 0, 0, 3, 0, 0, 2, 0, 0, 1, 0])

# set 2
new_chart.add('2-1',[0, 9, 0, 0, 8, 0, 0, 7, 0, 0, 6])
new_chart.add('2-2',[0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9])