- 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.
推薦閱讀
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- DBA攻堅指南:左手Oracle,右手MySQL
- 小程序實戰視頻課:微信小程序開發全案精講
- Java EE 6 企業級應用開發教程
- Oracle 11g從入門到精通(第2版) (軟件開發視頻大講堂)
- AngularJS深度剖析與最佳實踐
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- Mastering Kali Linux for Web Penetration Testing
- 用Flutter極速構建原生應用
- Backbone.js Blueprints
- Creating Mobile Apps with jQuery Mobile(Second Edition)
- INSTANT Yii 1.1 Application Development Starter
- SQL Server 2014 Development Essentials
- Mastering Python
- Java EE 程序設計