import colorsys

import matplotlib.pyplot as plt

import pandas as pd

labels = df.Gender.value_counts().index
N = len(df.EmploymentField.value_counts().index)
HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)]
RGB_tuples = list(map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples))
patches, texts = plt.pie(df.Gender.value_counts(), colors=RGB_tuples, startangle=90)
plt.axes().set_aspect('equal', 'datalim')
plt.legend(patches, labels, bbox_to_anchor=(1.05,1))
plt.title("Gender")
plt.show()

N = len(df.JobRoleInterest.value_counts().index)
HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)]
RGB_tuples = list(map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples))
labels = df.JobRoleInterest.value_counts().index
colors = ['OliveDrab', 'Orange', 'OrangeRed', 'DarkCyan', 'Salmon', 'Sienna', 'Maroon', 'LightSlateGrey', 'DimGray']
patches, texts = plt.pie(df.JobRoleInterest.value_counts(), colors=RGB_tuples, startangle=90)
plt.axes().set_aspect('equal', 'datalim')
plt.legend(patches, labels, bbox_to_anchor=(1.25, 1))
plt.title("Job Role Interest")
plt.show()

N = len(df.EmploymentField.value_counts().index)
HSV_tuples = [(x*1.0/N, 0.5, 0.5) for x in range(N)]
RGB_tuples = list(map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples))
labels = df.EmploymentField.value_counts().index
patches, texts = plt.pie(df.EmploymentField.value_counts(), colors=RGB_tuples, startangle=90)
plt.axes().set_aspect('equal', 'datalim')
plt.legend(patches, labels, bbox_to_anchor=(1.3, 1))
plt.title("Employment Field")
plt.show()

df_ageranges = df.copy()
bins = [0, 20, 30, 40, 50, 60, 100]
df_ageranges['AgeRanges'] = pd.cut(df_ageranges['Age'], bins, labels=['< 20', '20-30', '30-40', '40-50', '50-60', '< 60'])
df2 = pd.crosstab(df_ageranges.AgeRanges, df_ageranges.JobPref).apply(lambda r: r / r.sum(), axis=1)
N = len(df_ageranges.AgeRanges.value_counts().index)
HSV_tuples = [(x * 1.0 / N, 0.5, 0.5) for x in range(N)]
RGB_tuples = list(map(lambda x: colorsys.hsv_to_rgb(*x), HSV_tuples))
ax1 = df2.plot(kind='bar', stacked=True, color=RGB_tuples, title='Job preference per Age')
(lines, labels) = ax1.get_legend_handles_labels()
ax1.legend(lines, labels, bbox_to_anchor=(1.51, 1))