def plot_histogram(data, title, x_label, color):
"""
Generates an interactive histogram.
Args:
data (pd.Series): The data to plot.
title (str): The title of the plot.
x_label (str): Label for the x-axis.
color (str): Fill color for the histogram.
Returns:
None
"""
hist, edges = np.histogram(data, bins=50)
source = ColumnDataSource(data=dict(top=hist, left=edges[:-1], right=edges[1:]))
p = figure(title=title, x_axis_label=x_label, y_axis_label="Frequency",
width=800, height=400, x_range=(edges[0], edges[-1]))
p.quad(top='top', bottom=0, left='left', right='right', source=source,
fill_color=color, line_color="white", alpha=0.7)
hover = HoverTool(tooltips=[("Range", "@left{0.00} to @right{0.00}"), ("Count", "@top")])
p.add_tools(hover)
show(p)
# histograms for polarity and subjectivity
plot_histogram(df_cleaned['polarity'], "Distribution of Sentiment Polarity", "Polarity", "green")
print("\n")
plot_histogram(df_cleaned['subjectivity'], "Distribution of Review Subjectivity", "Subjectivity", "orange")