Created
August 16, 2017 06:28
-
-
Save kevingduck/4befd4329b25b374b9a20b8dffab6c79 to your computer and use it in GitHub Desktop.
Pie Chart Demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
''' | |
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" | |
* custom start angle | |
Note about the custom start angle: | |
The default ``startangle`` is 0, which would start the "Frogs" slice on the | |
positive x-axis. This example sets ``startangle = 90`` such that everything is | |
rotated counter-clockwise by 90 degrees, and the frog slice starts on the | |
positive y-axis. | |
''' | |
import matplotlib.pyplot as plt | |
# The slices will be ordered and plotted counter-clockwise. | |
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' | |
sizes = [15, 30, 45, 10] | |
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral'] | |
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs') | |
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=False, startangle=90) | |
# Set aspect ratio to be equal so that pie is drawn as a circle. | |
plt.axis('equal') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment