<jupyter_start><jupyter_text>This plot is for Baby Boomer, Generation X and Millennial<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

# You can read write or append
# The first line open the file with the intention of reading it
# readFile.read
#C:\Users\ane13003\OneDrive - University of Connecticut\CohortAnalysis\PythonPlots_Backup_2015
readFile = open('C:\\Users\\ane13003\\OneDrive - University of Connecticut\\CohortAnalysis\\PythonPlots_Backup_2015\\SocDem016August2017.txt','r')
sepFile = readFile.read().split('\n')
readFile.close()
# Will print the elements as strings
#print sepFile

# This variable will read duration for one age group
age_group = 2
dur = np.empty((0,age_group),int) #Read the whole file into an array # 2 columns, 2 age groups, 18-24 & 25-34
cnt_line = 0   # Counts the number of lines in the text file

for i in sepFile: # Read each line of the file
    cnt_line  = cnt_line + 1
    line = i.split(',') # Split the lines at the comma 
    #print line
    ls = []
    for j in range(0,age_group):
        ls.append(int(line[j])) #Append all the values of the line into a list
    #print ls
    dur = np.append(dur, np.array([ls]), axis=0) #Add the list into the duration array #Adds one line at a time to the duration array
#print dur     
# END OF READING THE DATA
#print 'how many lines in the text file? ', cnt_line

# DEFINITION OF SOME VARIABLES
cohorts = 3
Groups = 5
width = 0.18
# END OF DEFINITION OF THE VARIABLES

# This command creates the figure and axis in the same go
# ax is an no array, with 1 row and 2 columns
# Also you can pass parameters to tell it to share the y and the x axis
# f is the figure object, ax is a 1 by 2 array which is essentialy a row vector in this case
f,ax = plt.subplots(Groups,1, sharey = False, sharex = True, figsize = (10,10)) # The first number is the number of rows and 2nd number is the number of columns

# THIS SETS THE FONT SIZE FOR THE Y AXIS
axis_font = {'family' : 'cambria',
        'weight' : 'bold',
        'size'   : 16}

f.text(0.00, 0.55, 'Percentage(%) of People in Different Groups', va='center', rotation='vertical', **axis_font) # This is the common y-label for all the subplots
plt.xlabel('Age Groups in Years', **axis_font)
f.set_size_inches(6,6)  # This sets the figure size to be 9 inch by 6 inch  // 9 is the width and 6 is the height

# Adjusting are for the subplot
plt.subplots_adjust(left=0.05, right=0.97, top=0.95, bottom=0.14, hspace = 0.35) # hspace increases the space between the subplots

# Provide x tick lables
ind = np.arange(age_group)
print 'ind: ', ind
ax[0].set_xticks(ind+width*2)
ax[0].set_xticklabels( ('Age: 18-24 years','Age: 25-34 years'), **axis_font )

# Make the y axis labels invisible
for i in range(0,Groups):
    ax[i].yaxis.set_visible(False)
    
# Change the font size for all elements
font = {'family' : 'cambria',
        'weight' : 'bold',
        'size'   : 10}

# Setting the font
plt.rc('font', **font)
# END OF PLOT BBEAUTIFICATION

# THE MAIN FUNCTION THAT WILL CREATE THE PLOT
def create_subplot(matrix, colors, axis, title):
    bar_rend = [] # Define an empty list
    # ind is the x location of the vertical bars
    # Defined by how many columns are there in the matrix
    ind = np.arange(matrix.shape[1]) # get the column number of the passed matrix
    #print 'ind: ', ind
    # Set y limit for the matrix
    axis.set_ylim([0,1.25*matrix.max()])
    for i, row in enumerate(matrix):
        #print('row',row)
        r = axis.bar(ind+width*i,row, width, color = colors[i])
        #print type(r)
        bar_rend.append(r)
    axis.set_title(title)
    return bar_rend
# END OF THE MAIN FUNCTION

p = [] # An empty list to hold bar properties

# CALLING THE FUNCTION TO CREATE THE PLOT
# Defining the colosrs as a list #Colors and Labels would be same for all the age groups
c_1_colors = ['blue','orange', 'red'] # colors correspond to the generations, each row will be plotted using one color
sub_title = ['Living in Urban Area','Student','Worker','Unemployed',
             'Married'  ]
dum = 0
for i in range(0,Groups):
    c_1 = dur[dum:(dum+cohorts),] # Passing the matrix for one activity type at a time
    #print('i',c_1)
    p.extend(create_subplot(c_1, c_1_colors, ax[i],sub_title[i]))
    dum = dum + cohorts
# END OF CALL

# CREATING LABELS    
c_1_labels = ['Baby Boomer', 'Generation X', 'Millennial']    
    
f.legend(((x[0] for x in p)), # bar properties
        (c_1_labels ), 
         bbox_to_anchor=(0.52, 0), 
         loc='lower center', 
         ncol=5)
# END OF LABEL CREATION


# PROVIDE TEXT TO THE PLOT
def autolabel(rects, i):
    # attach some text labels
    for rect in rects:
        #print('rect', rect)
        height = rect.get_height()
        #print('height', height)
        if height > 0:
            ax[i].text(rect.get_x()+rect.get_width()/2., 1.00*height, '%d'%int(height),
                ha='center', va='bottom', **font)

for i in range(0,cnt_line):
    #print('i',i)
    autolabel(p[i], i/cohorts) #The last argument is the pointer to the axis, here we are doing an integer division
# END OF PROVIDING TEXT TO THE PLOT

#plt.show()

f.savefig('C:\\Users\\ane13003\\OneDrive - University of Connecticut\\CohortAnalysis\\PythonPlots_Backup_2015\\SocDem_01_06Aug2017.tif',dpi=300)<jupyter_output>ind:  [0 1]<jupyter_text>This plot is for GI Generation, Silent Generation and Baby Boomer<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

# You can read write or append
# The first line open the file with the intention of reading it
# readFile.read
#C:\Users\ane13003\OneDrive - University of Connecticut\CohortAnalysis\PythonPlots_Backup_2015
readFile = open('C:\\Users\\ane13003\\OneDrive - University of Connecticut\\CohortAnalysis\\PythonPlots_Backup_2015\\SocDem026August2017.txt','r')
sepFile = readFile.read().split('\n')
readFile.close()
# Will print the elements as strings
#print sepFile

# This variable will read duration for one age group
age_group = 2
dur = np.empty((0,age_group),int) #Read the whole file into an array # 2 columns, 2 age groups, 18-24 & 25-34
cnt_line = 0   # Counts the number of lines in the text file

for i in sepFile: # Read each line of the file
    cnt_line  = cnt_line + 1
    line = i.split(',') # Split the lines at the comma 
    #print line
    ls = []
    for j in range(0,age_group):
        ls.append(int(line[j])) #Append all the values of the line into a list
    #print ls
    dur = np.append(dur, np.array([ls]), axis=0) #Add the list into the duration array #Adds one line at a time to the duration array
#print dur     
# END OF READING THE DATA
#print 'how many lines in the text file? ', cnt_line

# DEFINITION OF SOME VARIABLES
cohorts = 3
Groups = 3
width = 0.18
# END OF DEFINITION OF THE VARIABLES

# This command creates the figure and axis in the same go
# ax is an no array, with 1 row and 2 columns
# Also you can pass parameters to tell it to share the y and the x axis
# f is the figure object, ax is a 1 by 2 array which is essentialy a row vector in this case
f,ax = plt.subplots(Groups,1, sharey = False, sharex = True, figsize = (10,10)) # The first number is the number of rows and 2nd number is the number of columns

# THIS SETS THE FONT SIZE FOR THE Y AXIS
axis_font = {'family' : 'cambria',
        'weight' : 'bold',
        'size'   : 16}

f.text(0.00, 0.55, 'Percentage(%) of People in Different Groups', va='center', rotation='vertical', **axis_font) # This is the common y-label for all the subplots
plt.xlabel('Age Groups in Years', **axis_font)
f.set_size_inches(6,6)  # This sets the figure size to be 9 inch by 6 inch  // 9 is the width and 6 is the height

# Adjusting are for the subplot
plt.subplots_adjust(left=0.05, right=0.97, top=0.95, bottom=0.14, hspace = 0.35) # hspace increases the space between the subplots

# Provide x tick lables
ind = np.arange(age_group)
print 'ind: ', ind
ax[0].set_xticks(ind+width*2)
ax[0].set_xticklabels( ('Age: 55-64 years','Age: >=65 years'), **axis_font )

# Make the y axis labels invisible
for i in range(0,Groups):
    ax[i].yaxis.set_visible(False)
    
# Change the font size for all elements
font = {'family' : 'cambria',
        'weight' : 'bold',
        'size'   : 10}

# Setting the font
plt.rc('font', **font)
# END OF PLOT BBEAUTIFICATION

# THE MAIN FUNCTION THAT WILL CREATE THE PLOT
def create_subplot(matrix, colors, axis, title):
    bar_rend = [] # Define an empty list
    # ind is the x location of the vertical bars
    # Defined by how many columns are there in the matrix
    ind = np.arange(matrix.shape[1]) # get the column number of the passed matrix
    #print 'ind: ', ind
    # Set y limit for the matrix
    axis.set_ylim([0,1.25*matrix.max()])
    for i, row in enumerate(matrix):
        #print('row',row)
        r = axis.bar(ind+width*i,row, width, color = colors[i])
        #print type(r)
        bar_rend.append(r)
    axis.set_title(title)
    return bar_rend
# END OF THE MAIN FUNCTION

p = [] # An empty list to hold bar properties

# CALLING THE FUNCTION TO CREATE THE PLOT
# Defining the colosrs as a list #Colors and Labels would be same for all the age groups
c_1_colors = ['yellow','green', 'blue'] # colors correspond to the generations, each row will be plotted using one color
sub_title = ['Living in Urban Area','Worker','Retired'  ]
dum = 0
for i in range(0,Groups):
    c_1 = dur[dum:(dum+cohorts),] # Passing the matrix for one activity type at a time
    #print('i',c_1)
    p.extend(create_subplot(c_1, c_1_colors, ax[i],sub_title[i]))
    dum = dum + cohorts
# END OF CALL

# CREATING LABELS    
c_1_labels = ['GI Generation','Silent Generation','Baby Boomer']    
    
f.legend(((x[0] for x in p)), # bar properties
        (c_1_labels ), 
         bbox_to_anchor=(0.52, 0), 
         loc='lower center', 
         ncol=5)
# END OF LABEL CREATION


# PROVIDE TEXT TO THE PLOT
def autolabel(rects, i):
    # attach some text labels
    for rect in rects:
        #print('rect', rect)
        height = rect.get_height()
        #print('height', height)
        if height > 0:
            ax[i].text(rect.get_x()+rect.get_width()/2., 1.00*height, '%d'%int(height),
                ha='center', va='bottom',**font)

for i in range(0,cnt_line):
    #print('i',i)
    autolabel(p[i], i/cohorts) #The last argument is the pointer to the axis, here we are doing an integer division
# END OF PROVIDING TEXT TO THE PLOT

#plt.show()

f.savefig('C:\\Users\\ane13003\\OneDrive - University of Connecticut\\CohortAnalysis\\PythonPlots_Backup_2015\\SocDem_02_06Aug2017.tif',dpi=300)<jupyter_output>ind:  [0 1]
{'fraction_non_alphanumeric': 0.11208521870286577, 'fraction_numerical': 0.027526395173453996, 'mean_word_length': 3.4820447824250107, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '224389', 'license': 'MIT', 'n_tokens_mistral': 3784, 'n_tokens_neox': 3511, 'n_words': 1311, 'path': '04 CohortAnalysis/SocDemCohort6August2017.ipynb', 'repo_name': 'ProtitiAnnesha/DissertationResearch', 'size': '10608'}