- matplotlib Plotting Cookbook
- Alexandre Devert
- 131字
- 2021-07-16 12:16:26
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 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.
推薦閱讀
- Designing Machine Learning Systems with Python
- Python自然語(yǔ)言處理(微課版)
- Python 3破冰人工智能:從入門(mén)到實(shí)戰(zhàn)
- Java設(shè)計(jì)模式及實(shí)踐
- Responsive Web Design by Example
- 程序員修煉之道:通向務(wù)實(shí)的最高境界(第2版)
- Python Web數(shù)據(jù)分析可視化:基于Django框架的開(kāi)發(fā)實(shí)戰(zhàn)
- Tableau 10 Bootcamp
- HTML5 APP開(kāi)發(fā)從入門(mén)到精通(微課精編版)
- Learning Apache Cassandra
- Android開(kāi)發(fā)三劍客:UML、模式與測(cè)試
- Building Wireless Sensor Networks Using Arduino
- Python函數(shù)式編程(第2版)
- SQL Server 2008中文版項(xiàng)目教程(第3版)
- Python開(kāi)發(fā)基礎(chǔ)