def freq_plot_to_show(results): """ displays bar plot of relative frequency of all words in results :param results: dict of results from dunning_total or similar, i.e. in the form {'word': { 'freq_corp1': int, 'freq_corp2': int, 'freq_total': int}} :return: None, displays bar plot of relative frequency of all words in results """ load_graph_settings(False) results_dict = dict(results) words = [] female_rel_freq = [] male_rel_freq = [] for term, data in results_dict.items(): words.append(term) female_rel_freq.append(data['freq_corp1'] / data['freq_total']) male_rel_freq.append(-1 * data['freq_corp2'] / data['freq_total']) opacity = 0.4 colors = ['b'] ax = sns.barplot(male_rel_freq, words, palette=colors, alpha=opacity) sns.despine(ax=ax, bottom=True, left=True) plt.show()
def box_gender_pronoun_freq(freq_dict, my_pal, title, x="N/A"): """ Takes in a frequency dictionary (from **freq_by_author_gender**, **freq_by_date**, or **freq_by_location**) and exports its values as a bar-and-whisker graph :param freq_dict: dictionary of frequencies :param my_pal: palette to be used :param title: title of exported graph :param x: name of x-vars :return: None """ plt.clf() groups = [] val = [] for k, v in freq_dict.items(): temp = [k]*len(v) groups.extend(temp) val.extend(v) df = pd.DataFrame({x: groups, 'Frequency': val}) df = df[[x, 'Frequency']] common.load_graph_settings() sns.boxplot(x=df[x], y=df['Frequency'], palette=my_pal).set_title("Relative Frequency of Female Pronouns to Total Pronouns") plt.xticks(rotation=90) # plt.show() filepng = "visualizations/" + title + ".png" filepdf = "visualizations/" + title + ".pdf" plt.savefig(filepng, bbox_inches='tight') plt.savefig(filepdf, bbox_inches='tight')
def box_plots(inst_data, my_pal, title, x="N/A"): """ Takes in a frequency dictionaries and exports its values as a bar-and-whisker graph :param inst_data: Dictionary containing instance distance data (from one of the other functions in the module) :param my_pal: str, seaborn palette to be used :param title: str, filename of exported graph :param x: name of x-vars :return: None """ plt.clf() groups = [] val = [] for k, v in inst_data.items(): temp1 = [] for el in v: if el[1] <= 60: temp1.append(el[1]) temp2 = [k.replace("_", " ").capitalize()] * len(temp1) val.extend(temp1) groups.extend(temp2) df = pnds.DataFrame({x: groups, 'Median Female Instance Distance': val}) df = df[[x, 'Median Female Instance Distance']] common.load_graph_settings() sns.boxplot(x=df[x], y=df['Median Female Instance Distance'], palette=my_pal).set_title(title) plt.xticks(rotation=90) # plt.show() filepng = "visualizations/" + title + ".png" filepdf = "visualizations/" + title + ".pdf" plt.savefig(filepng, bbox_inches='tight') plt.savefig(filepdf, bbox_inches='tight')
def score_plot_to_show(results): """ displays bar plot of dunning scores for all words in results :param results: dict of results from dunning_total or similar, i.e. in the form {'word': { 'dunning': float}} :return: None, displays bar plot of dunning scores for all words in results """ load_graph_settings(False) results_dict = dict(results) words = [] dunning_score = [] for term, data in results_dict.items(): words.append(term) dunning_score.append(data['dunning']) opacity = 0.4 colors = ['r' if entry >= 0 else 'b' for entry in dunning_score] ax = sns.barplot(dunning_score, words, palette=colors, alpha=opacity) sns.despine(ax=ax, bottom=True, left=True) plt.show()