Skip to content

Instantly share code, notes, and snippets.

@dradecic
Created September 29, 2019 10:26
Show Gist options
  • Save dradecic/1f1d1519e55e3875942c927136161603 to your computer and use it in GitHub Desktop.
Save dradecic/1f1d1519e55e3875942c927136161603 to your computer and use it in GitHub Desktop.
recommender1_bar_chart
def make_bar_chart(dataset, attribute, bar_color='#3498db', edge_color='#2980b9', title='Title', xlab='X', ylab='Y', sort_index=False):
if sort_index == False:
xs = dataset[attribute].value_counts().index
ys = dataset[attribute].value_counts().values
else:
xs = dataset[attribute].value_counts().sort_index().index
ys = dataset[attribute].value_counts().sort_index().values
fig, ax = plt.subplots(figsize=(14, 7))
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.set_title(title, fontsize=24, pad=20)
ax.set_xlabel(xlab, fontsize=16, labelpad=20)
ax.set_ylabel(ylab, fontsize=16, labelpad=20)
plt.bar(x=xs, height=ys, color=bar_color, edgecolor=edge_color, linewidth=2)
plt.xticks(rotation=45)
make_bar_chart(genre_df, 'Genre', title='Most Popular Movie Genres', xlab='Genre', ylab='Counts')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment