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

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.

主站蜘蛛池模板: 马尔康县| 玉溪市| 萨嘎县| 木里| 蕉岭县| 清流县| 旬阳县| 香港| 措美县| 西林县| 山阳县| 阿克苏市| 浙江省| 措勤县| 南木林县| 临猗县| 鄯善县| 达尔| 东海县| 长春市| 连江县| 云南省| 松滋市| 东莞市| 开平市| 确山县| 东明县| 绥棱县| 长阳| 潞西市| 安仁县| 大名县| 防城港市| 陆川县| 临汾市| 雷州市| 扎兰屯市| 古浪县| 富阳市| 察隅县| 定远县|