饼图切片上的行值python

时间:2019-03-19 22:54:26

标签: python pandas

我有以下数据集:

import matplotlib.pyplot as plotter

    pieLabels              = 'Asia', 'Africa', 'Europe', 'North America', 'South America', 'Australia'
    populationShare     = [5.69, 16, 9.94, 7.79, 5.68, 6.54]

制作馅饼:

figureObject, axesObject = plotter.subplots()
axesObject.pie(populationShare,
        labels=pieLabels,
        startangle=90)
axesObject.axis('equal')
plotter.show()

我想制作一个饼图,并在饼图的切片上打印出种群总数的实际值。不是一个百分比。

1 个答案:

答案 0 :(得分:1)

尝试如下操作:

import matplotlib.pyplot as plotter

pieLabels  = ['Asia', 'Africa', 'Europe', 'North America', 'South America', 'Australia']
populationShare = [5.69, 16, 9.94, 7.79, 5.68, 6.54]

figureObject, axesObject = plotter.subplots()
axesObject.pie(populationShare,
               labels=pieLabels,
               autopct=lambda p: '{:.2f}'.format(p * sum(populationShare) / 100),
               startangle=90)
axesObject.axis('equal')
plotter.show()