Skip to content

Instantly share code, notes, and snippets.

@josht-jpg
Last active September 7, 2020 19:36
Show Gist options
  • Save josht-jpg/95d1120f90a8aad6125a9537c1bb5996 to your computer and use it in GitHub Desktop.
Save josht-jpg/95d1120f90a8aad6125a9537c1bb5996 to your computer and use it in GitHub Desktop.
Plot NRC
def plot_nrc(df, title):
i = 0
j = 0
scores = pd.DataFrame(np.zeros((df.shape[0] // 750, 10)), columns = NRC_sentiments)
while i < df.shape[0] - 750:
scores.iloc[j] = df.loc[i:i + 750, 'anger':'trust'].sum()
i += 750
j += 1
grid_kws = {"height_ratios": (.9, .05), "hspace": .2}
f, (ax, cbar_ax) = plt.subplots(2, gridspec_kw=grid_kws, figsize=(10,3))
ax = sns.heatmap(scores.transpose(),
ax=ax,
cbar_ax=cbar_ax,
cbar_kws={"orientation": "horizontal", "label" : \
"Number of words conveying sentiment"},
linewidths = 0.01,
xticklabels = False,
vmin = 0,
vmax = 125).set_title(title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment