注解
Click here 下载完整的示例代码
基本饼图¶
演示一个基本的饼图以及一些附加功能。
除了基本饼图之外,本演示还显示了一些可选功能:
- 切片标签
- 自动标记百分比
- 用“explode”偏移切片
- 阴影
- 自定义起始角度
有关自定义起始角度的说明:
默认值 startangle
是0,它将在正x轴上开始“frogs”切片。此示例集 startangle = 90
这样,所有的东西都是逆时针旋转90度,青蛙片从正Y轴开始。
import matplotlib.pyplot as plt
# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()

工具书类¶
以下函数、方法、类和模块的使用如本例所示:
import matplotlib
matplotlib.axes.Axes.pie
matplotlib.pyplot.pie
出:
<function pie at 0x7faa00cfd048>
关键词:matplotlib代码示例,codex,python plot,pyplot Gallery generated by Sphinx-Gallery