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

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.

主站蜘蛛池模板: 锡林浩特市| 赤壁市| 石首市| 仁布县| 治县。| 顺平县| 大关县| 广宗县| 台江县| 张家港市| 泽库县| 梅河口市| 陇西县| 上虞市| 萨迦县| 五大连池市| 延边| 德兴市| 石棉县| 二连浩特市| 电白县| 库车县| 永德县| 若尔盖县| 迁西县| 灵丘县| 阜新| 景谷| 高平市| 麟游县| 怀集县| 泰宁县| 通河县| 安西县| 枣庄市| 洪雅县| 潮州市| 大渡口区| 炎陵县| 府谷县| 光山县|