## How to generate PIE plot in Python
def Snippet_118():
print()
print(format('How to generate PIE plot in Python','*^82'))
import warnings
warnings.filterwarnings("ignore")
# load libraries
import pandas as pd
import matplotlib.pyplot as plt
# Create dataframe
raw_data = {'officer_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'jan_arrests': [4, 24, 31, 2, 3],
'feb_arrests': [25, 94, 57, 62, 70],
'march_arrests': [5, 43, 23, 23, 51]}
df = pd.DataFrame(raw_data, columns = ['officer_name', 'jan_arrests',
'feb_arrests', 'march_arrests'])
print(); print(df)
# Create a column with the total arrests for each officer
df['total_arrests'] = df['jan_arrests'] + df['feb_arrests'] + df['march_arrests']
print(); print(df)
# Create a list of colors (from iWantHue)
colors = ["#E13F29", "#D69A80", "#D63B59", "#AE5552", "#CB5C3B", "#EB8076", "#96624E"]
# Create a pie chart
plt.pie(df['total_arrests'], labels=df['officer_name'], shadow=False,
colors=colors, explode=(0, 0, 0, 0, 0.15), startangle=90, autopct='%1.1f%%')
# View the plot drop above
plt.axis('equal')
plt.tight_layout(); plt.show()
Snippet_118()