Raincloud Plot
Book Rating by Genre
Reader ratings across book categories
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt
np.random.seed(216)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#F527B0', '#276CF5', '#F5B027', '#6CF527']
genres = ['Fiction', 'Non-Fiction', 'Mystery', 'Romance']
data = pd.DataFrame({
'Rating': np.concatenate([
np.random.beta(7, 2, 100) * 5,
np.random.beta(8, 2.5, 90) * 5,
np.random.beta(7.5, 2, 85) * 5,
np.random.beta(6.5, 2.5, 95) * 5
]),
'Genre': ['Fiction']*100 + ['Non-Fiction']*90 + ['Mystery']*85 + ['Romance']*95
})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
pt.RainCloud(x='Genre', y='Rating', data=data, palette=COLORS,
bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
dodge=True, pointplot=False, move=.2)
ax.set_xlabel('Rating (out of 5)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Genre', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Book Ratings by Genre', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#e5e7eb')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕