Created
December 2, 2020 15:50
-
-
Save manmohan24nov/64bb314bc22814b03212f57aa181c461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import cm | |
list1x = list(reddit_subgroup_name_df['subgroup']) | |
list1y = list(reddit_subgroup_name_df['positive']) | |
list1z = list(reddit_subgroup_name_df['negative']) | |
x = np.arange(len(list1x)) # the label locations | |
width = 0.35 # the width of the bars | |
fig, ax = plt.subplots(figsize=(15, 8)) | |
rects1 = ax.bar(x - width/2, list1y, width, label='positive') | |
rects2 = ax.bar(x + width/2, list1z, width, label='negative') | |
plt.rcParams.update({'font.size': 10}) | |
rects = ax.patches | |
def autolabel(rects): | |
"""Attach a text label above each bar in *rects*, displaying its height.""" | |
for rect in rects: | |
height = rect.get_height() | |
ax.annotate('{}'.format(height), | |
xy=(rect.get_x() + rect.get_width() / 2, height), | |
xytext=(0, 3), # 3 points vertical offset | |
textcoords="offset points", | |
ha='center', va='bottom') | |
autolabel(rects1) | |
autolabel(rects2) | |
ax.text(0, 1.02, 'Count of Positive and Negative comments', | |
transform=ax.transAxes, size=12, weight=600, color='#777777') | |
ax.xaxis.set_ticks_position('bottom') | |
ax.tick_params(axis='x', colors='black', labelsize=9) | |
ax.set_xticklabels(list1x) | |
ax.set_xticks(x) | |
ax.legend() | |
ax.set_axisbelow(True) | |
ax.text(0, 1.08, 'Sentiment Analysis of Reddit Subgroup', | |
transform=ax.transAxes, size=22, weight=600, ha='left') | |
ax.text(0, -0.1, 'Source: Reddit subgroup Comments (https://www.reddit.com/)', | |
transform=ax.transAxes, size=12, weight=200, color='#777777') | |
ax.spines['right'].set_visible(False) | |
ax.spines['top'].set_visible(False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment