Bubble Chart

Investment Portfolio Bubble

Asset classes by return, volatility, and allocation percentage.

Output
Investment Portfolio Bubble
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')

assets = ['US Stocks', 'Intl Stocks', 'Bonds', 'Real Estate', 'Gold', 'Crypto', 'Cash', 'Commodities']
returns = np.array([10.5, 8.2, 4.5, 9.1, 6.8, 45, 2.5, 5.5])
volatility = np.array([16, 18, 4, 12, 15, 75, 0.5, 18])
allocation = np.array([40, 15, 20, 10, 5, 3, 5, 2])

colors = ['#276CF5', '#4927F5', '#6CF527', '#F5B027', '#F5D327', '#F54927', '#27D3F5', '#F5276C']
sizes = allocation * 40

for glow_mult, glow_alpha in [(2.0, 0.03), (1.6, 0.05), (1.3, 0.08)]:
    ax.scatter(volatility, returns, s=sizes*glow_mult, c='#000000', alpha=glow_alpha, edgecolors='none')

ax.scatter(volatility, returns, s=sizes, c=colors, alpha=0.85, edgecolors='white', linewidth=2)
ax.scatter(volatility - np.sqrt(sizes)*0.1, returns + np.sqrt(sizes)*0.08, s=sizes*0.2, c='white', alpha=0.6, edgecolors='none')

for i, asset in enumerate(assets):
    offset_y = np.sqrt(sizes[i])/2 + 10
    ax.annotate(asset, (volatility[i], returns[i]), fontsize=10, color='#1f2937',
                ha='center', va='bottom', xytext=(0, offset_y), textcoords='offset points', fontweight='bold')

ax.text(0.0, 1.08, 'Investment Portfolio', transform=ax.transAxes, fontsize=24, color='#1f2937', fontweight='bold')
ax.text(0.0, 1.02, 'Volatility vs Return · Bubble size = Allocation', transform=ax.transAxes, fontsize=11, color='#6b7280')

ax.set_xlabel('Volatility (Std Dev %)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.set_ylabel('Annual Return (%)', fontsize=14, color='#4b5563', fontweight='500', labelpad=15)
ax.tick_params(colors='#6b7280', labelsize=11, length=0)

for y in [0, 10, 20, 30, 40, 50]:
    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

Did this help you?

Support PyLucid to keep it free & growing

Support