Bubble Chart
E-commerce Products Analysis
Product categories by price, sales volume, and customer ratings.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
fig, ax = plt.subplots(figsize=(14, 9), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
products = ['Electronics', 'Fashion', 'Home', 'Books', 'Sports', 'Beauty', 'Toys', 'Food']
price = np.array([450, 85, 120, 22, 95, 45, 35, 28])
sales = np.array([850, 2200, 1100, 950, 680, 1500, 780, 3200])
rating = np.array([4.3, 4.1, 4.4, 4.6, 4.2, 4.5, 4.3, 4.4])
colors = ['#27D3F5', '#F5276C', '#F5B027', '#6CF527', '#F54927', '#F527B0', '#4927F5', '#27F5B0']
sizes = rating * 250
for glow_mult, glow_alpha in [(2.0, 0.03), (1.6, 0.05), (1.3, 0.08)]:
ax.scatter(price, sales, s=sizes*glow_mult, c='#000000', alpha=glow_alpha, edgecolors='none')
ax.scatter(price, sales, s=sizes, c=colors, alpha=0.85, edgecolors='white', linewidth=2)
ax.scatter(price - np.sqrt(sizes)*0.3, sales + np.sqrt(sizes)*2, s=sizes*0.2, c='white', alpha=0.6, edgecolors='none')
for i, product in enumerate(products):
offset_y = np.sqrt(sizes[i])/2 + 10
ax.annotate(product, (price[i], sales[i]), fontsize=11, color='#1f2937',
ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')
ax.text(0.0, 1.08, 'E-commerce Products', transform=ax.transAxes, fontsize=24, color='#1f2937', fontweight='bold')
ax.text(0.0, 1.02, 'Price vs Sales · Bubble size = Rating', transform=ax.transAxes, fontsize=11, color='#6b7280')
ax.set_xlabel('Average Price ($)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.set_ylabel('Monthly Sales (K)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.tick_params(colors='#6b7280', labelsize=11, length=0)
for y in [0, 1000, 2000, 3000, 4000]:
ax.axhline(y=y, color='#f3f4f6', linewidth=1, zorder=0)
for spine in ax.spines.values():
spine.set_visible(False)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Bubble Chart examples
☕