We use the same graphs as that in the PDF
In [2]:
import os
os.chdir("/home/archimedeas/wrkspc/anaconda/major_1/datasets/1_the_senate_datasets")
In [ ]:
import pandas as pd
import numpy as np
from bokeh._legacy_charts import output_notebook, show
import bokeh
df = pd.read_csv("1_age_group_5yr_span.csv", index_col = 0)
df
In [ ]:
df.shape
In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = (10.0, 8.0)
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
N = 5
menMeans = (20, 35, 30, 35, 27)
menStd = (2, 3, 4, 1, 2)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color = 'red', alpha = 0.6)
womenMeans = (25, 32, 34, 20, 25)
womenStd = (3, 5, 2, 3, 3)
rects2 = ax.bar(ind + width, womenMeans, width )
# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(('Frogs', 'Hogs', 'Bogs', 'Slogs', 'Kerebos'))
ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
plt.show()
In [ ]:
import matplotlib.pyplot as plt
import pandas as pd
# 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.1, 0.1, 0.1, 0.1)
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.show()
In [ ]:
df_men = pd.read_csv("1_age_group_5yr_span.csv")
In [ ]:
ls_labels_men = []
ls_values_men = []
for i in range(1,df_men.shape[0]):
ls_labels_men.append(str(df_men.iat[i,0]))
ls_values_men.append(float(df_men.iat[i,1]))
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
N = len(ls_labels_men)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, ls_values_men, width, color = 'red', alpha = 0.6)
#rects2 = ax.bar(ind + width, ls_values_men, width )
# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(ls_labels_men)
#ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
plt.show()
In [ ]:
df_women = pd.read_csv("8_women_age_group.csv")
In [ ]:
ls_labels_women = []
ls_values_women = []
for i in range(1,df_women.shape[0]):
ls_labels_women.append(str(df_women.iat[i,0]))
ls_values_women.append(float(df_women.iat[i,1]))
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
N = len(ls_labels_women)
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
#rects1 = ax.bar(ind, ls_values_women, width, color = 'red', alpha = 0.6)
rects2 = ax.bar(ind + width, ls_values_women, width )
# add some text for labels, title and axes ticks
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.set_xticks(ind + width)
ax.set_xticklabels(ls_labels_women)
#ax.legend((rects1[0], rects2[0]), ('Men', 'Women'))
plt.show()
In [3]:
import pandas as pd
df_men = pd.read_csv("4_educational_background.csv")
In [4]:
df_men
Out[4]:
In [5]:
ls_labels_men = []
ls_values_men = []
for i in range(1,df_men.shape[0]):
ls_labels_men.append(str(df_men.iat[i,0]))
ls_values_men.append(float(df_men.iat[i,1]))
In [6]:
len(ls_labels_men)
Out[6]:
In [7]:
import matplotlib.pyplot as plt
import pandas as pd
plt.rcParams['figure.figsize'] = (10.0, 10.0)
# The slices will be ordered and plotted counter-clockwise.
labels = ls_labels_men
sizes = ls_values_men
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral', 'red', 'lightgreen']
#explode = (0.1, 0.1, 0.1, 0.1, 0, 0)
p, text = plt.pie(sizes, labels=labels, colors = colors, shadow=True, startangle=90 )
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
#plt.title("Educational Background", fontsize = 50, loc = 'right')
plt.legend(p, labels, loc= 'lower right')
plt.show()
In [ ]: