【python图像处理】python绘制饼状图

来源:互联网 发布:国内 阿里云 aws 优势 编辑:程序博客网 时间:2024/05/17 12:49

饼状图在统计分析中有着重要的应用,python中用于绘制饼状图是matplotlib中的pyplot类,这里就介绍一下,如何绘制饼状图。

直接看下面的代码

"""===============Basic pie chart===============Demo of a basic pie chart plus a few additional features.In addition to the basic pie chart, this demo shows a few optional features:    * slice labels    * auto-labeling the percentage    * offsetting a slice with "explode"    * drop-shadow    * custom start angleNote about the custom start angle:The default ``startangle`` is 0, which would start the "Frogs" slice on thepositive x-axis. This example sets ``startangle = 90`` such that everything isrotated counter-clockwise by 90 degrees, and the frog slice starts on thepositive y-axis."""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()

绘制结果如下图所示:



2017.09.19

原创粉丝点击