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

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.

主站蜘蛛池模板: 泸西县| 红河县| 南木林县| 方山县| 庄浪县| 太谷县| 富锦市| 卢龙县| 明光市| 金湖县| 北安市| 柳州市| 定南县| 乌海市| 雅安市| 林口县| 凤山市| 叙永县| 闽清县| 武隆县| 北安市| 利辛县| 祁连县| 咸丰县| 西畴县| 福泉市| 和田县| 建平县| 遂溪县| 黄梅县| 洛隆县| 平凉市| 鄄城县| 田阳县| 锦州市| 双辽市| 孝义市| 馆陶县| 河间市| 绥中县| 曲麻莱县|