# -*- coding: utf-8 -*-
"""Spiderplot arrests.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1ubG-AX0h53RTrbSFIh7TffHoey3CBiMJ
"""

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pylab
from math import pi

from google.colab import files
uploaded = files.upload()

data_path = "arrestspiderplotdata5.csv"
arrests = pd.read_csv(data_path, index_col=0)
print(arrests)

arrests2 = arrests.drop(arrests.columns[[0, 1, 2, 3, 4, 5]], axis=1)

arrests2

import matplotlib.pyplot as plt
import pandas as pd
from math import pi
 
df = pd.DataFrame({'r' : ['England & Wales', 'Massachusetts', 'Florida', 'Oregon', 'South Dakota'],
                   'England & Wales' : 0.022853,
                   'Massachusetts' : 0.014690,
                   'Florida' : 0.038576,
                   'Oregon' : 0.009410,
                   'South Dakota' : 0.071081
                   })


categories = list(df)[1:]
N = len(categories)


# What will be the angle of each axis in the plot? (we divide the plot / number of variable)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]
 
# Initialise the spider plot
ax = plt.subplot(111, polar=True)
 
# If you want the first axis to be on top:
ax.set_theta_offset(pi / 2)
ax.set_theta_direction(-1)
 
# Draw one axe per variable + add labels labels yet
plt.xticks(angles[:-1], df.index)
 
# Draw ylabels
ax.set_rlabel_position(0)
plt.yticks([0,0.025,0.05,0.075,0.1], ["0","0.025","0.05","0.075","0.1"], color="grey", size=7)
plt.ylim(0,0.1)
 
# ------- PART 2: Add plots
 
# Plot each individual = each line of the data
# I don't do a loop, because plotting more than 3 groups makes the chart unreadable
 
# Ind1
categories = list(df)[1:]
N = len(categories)

values=df.loc[0].drop('r').values.flatten().tolist()
values += values[:1]
values

angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]

ax = plt.subplot(111, polar=True)
plt.xticks(angles[:-1], categories, color='grey', size=8)
ax.set_rlabel_position(0)
plt.yticks([0,0.025,0.05,0.075,0.1], ["0","0.025","0.05","0.075","0.1"], color="grey", size=7)
plt.ylim(0, 0.1)
plt.title("Difference in arrest rate between White and Black people in England & Wales, Massachusetts, Florida, Oregon and South Dakota" + "\n")

ax.plot(angles, values, linewidth=1, linestyle='solid')
ax.fill(angles, values, 'b', alpha=0.1)