I have been wrestling with trying to add some extra details to my histogram but none of the solutions seem to work (e.g. Adding data labels ontop of my histogram Python/Matplotlib); maybe because my histogram is at the end of a long process (this code works). Any ideas how to add in? I thought it might have to go in def make_plot(): but most solutions have the details a bit different. I also tried to add in (How to plot a histogram using Matplotlib in Python with a list of data?) but I think it suffers from the same problem of where to put it in the script. I am new to this so forgive me if it is obvious. Thanks!
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
def save_fig(fig_id, tight_layout=True, fig_extension="png", resolution=900):
path = os.path.join(IMAGES_PATH, fig_id + "." + fig_extension)
print("Saving figure", fig_id)
if tight_layout:
plt.tight_layout()
plt.savefig(path, format=fig_extension, dpi=resolution)
def make_plot():
plt.figure(figsize=(8, 6))
df_vaderized['vader_compound'].plot(kind='hist', bins = 15, color='thistle')
plt.ylabel('Frequency')
plt.title('t0 sentiment analysis')
plt.grid(True)
plt.savefig('/content/t0_5.png')
# Just calling the function
make_plot()
This doesn't work based off (Adding data labels ontop of my histogram Python/Matplotlib). Instead I get AttributeError: module 'matplotlib.pyplot' has no attribute 'bar_label'.
def make_plot():
plt.figure(figsize=(8, 6))
values, bins, bars = plt.hist(t0wordcloudtext_df['afinn_adjusted'], bins = 15, edgecolor='white')
plt.bar_label(bars, fontsize=20, color='navy')
plt.margins(x=0.01, y=0.1)
# t0wordcloudtext_df['afinn_adjusted'].plot(kind='hist', bins = 15, color='salmon')
plt.ylabel('Frequency')
plt.xlabel('Adjusted AFINN')
plt.title('t0 AFINN sentiment analysis ')
plt.grid(True)