3D Scatter

Stock Universe: Risk-Return-Size

3D scatter of stocks showing relationship between volatility, returns, and market capitalization.

Output
Stock Universe: Risk-Return-Size
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(777)

# Stock data: volatility vs return vs market cap
n_stocks = 100

volatility = np.random.exponential(15, n_stocks) + 5
returns = np.random.normal(8, 20, n_stocks)
market_cap = np.random.exponential(50, n_stocks) + 10  # Billions

# Color by sector (5 sectors)
sectors = np.random.randint(0, 5, n_stocks)
sector_colors = ['#06b6d4', '#22c55e', '#f59e0b', '#ec4899', '#8b5cf6']
colors = [sector_colors[s] for s in sectors]

fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')

ax.scatter(volatility, returns, market_cap, c=colors, s=market_cap*2, alpha=0.7, edgecolors='white', linewidths=0.3)

ax.set_xlabel('Volatility (%)', color='white', fontsize=10)
ax.set_ylabel('Return (%)', color='white', fontsize=10)
ax.set_zlabel('Market Cap ($B)', color='white', fontsize=10)
ax.set_title('Stock Universe: Risk-Return-Size', color='white', fontsize=14, fontweight='bold', pad=20)

ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')

ax.view_init(elev=20, azim=35)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support