-
-
Save amankharwal/65a5c286d4eb652f93a076e0ea89c1c3 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
n_best = 20 | |
top_authors = df.Author.value_counts().nlargest(n_best) | |
no_dup = df.drop_duplicates('Name') # removes all rows with duplicate book names | |
fig, ax = plt.subplots(1, 3, figsize=(11,10), sharey=True) | |
color = sns.color_palette("hls", n_best) | |
ax[0].hlines(y=top_authors.index , xmin=0, xmax=top_authors.values, color=color, linestyles='dashed') | |
ax[0].plot(top_authors.values, top_authors.index, 'go', markersize=9) | |
ax[0].set_xlabel('Number of appearences') | |
ax[0].set_xticks(np.arange(top_authors.values.max()+1)) | |
ax[0].set_yticklabels(top_authors.index, fontweight='semibold') | |
ax[0].set_title('Appearences') | |
book_count = [] | |
total_reviews = [] | |
for name, col in zip(top_authors.index, color): | |
book_count.append(len(no_dup[no_dup.Author == name]['Name'])) | |
total_reviews.append(no_dup[no_dup.Author == name]['Reviews'].sum()/1000) | |
ax[1].hlines(y=top_authors.index , xmin=0, xmax=book_count, color=color, linestyles='dashed') | |
ax[1].plot(book_count, top_authors.index, 'go', markersize=9) | |
ax[1].set_xlabel('Number of unique books') | |
ax[1].set_xticks(np.arange(max(book_count)+1)) | |
ax[1].set_title('Unique books') | |
ax[2].barh(y=top_authors.index, width=total_reviews, color=color, edgecolor='black', height=0.7) | |
for name, val in zip(top_authors.index, total_reviews): | |
ax[2].text(val+2, name, val) | |
ax[2].set_xlabel("Total Reviews (in 1000's)") | |
ax[2].set_title('Total reviews') | |
#plt.suptitle('Top 20 best selling Authors (from 2009 to 2019) details', fontsize=15) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment