官术网_书友最值得收藏!

Plotting pie charts

To compare the relative importance of quantities, nothing like a good old pie—pie chart, that is.

How to do it...

The dedicated pie-plotting function pyplot.pie() will do the job. We will use this function in the following code:

import matplotlib.pyplot as plt

data = [5, 25, 50, 20]

  plt.pie(data)
plt.show()

The preceding simple script will display the following pie diagram:

How to do it...

How it works...

The pyplot.pie() function simply takes a list of values as the input. Note that the input data is a list; it could be a NumPy array. You do not have to adjust the data so that it adds up to 1 or 100. You just have to give values to matplolib and it will automatically compute the relative areas of the pie chart.

主站蜘蛛池模板: 新丰县| 长子县| 拜城县| 循化| 临安市| 南靖县| 万全县| 兰州市| 泸西县| 荣昌县| 盖州市| 遵义市| 含山县| 北川| 仙桃市| 凭祥市| 册亨县| 改则县| 呼伦贝尔市| 青州市| 从江县| 通州区| 岑巩县| 广宗县| 安乡县| 务川| 茶陵县| 秭归县| 三亚市| 荣昌县| 邵阳市| 修武县| 汝南县| 囊谦县| 浪卡子县| 石泉县| 射洪县| 沂南县| 桂平市| 万山特区| 凤庆县|