Faceted Scatter Plot
Market Returns by Sector
Faceted analysis of risk-return relationship across industry sectors
Output
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
np.random.seed(456)
sectors = ['Tech', 'Healthcare', 'Finance', 'Energy']
data = []
for sector in sectors:
n = 45
volatility = np.random.uniform(5, 35, n)
betas = {'Tech': 0.35, 'Healthcare': 0.25, 'Finance': 0.28, 'Energy': 0.22}
returns = betas[sector] * volatility + np.random.normal(0, 3, n)
for v, r in zip(volatility, returns):
data.append({'Volatility (%)': v, 'Annual Return (%)': r, 'Sector': sector})
df = pd.DataFrame(data)
plt.style.use('dark_background')
sns.set_style("darkgrid", {
'axes.facecolor': '#0a0a0f',
'figure.facecolor': '#0a0a0f',
'grid.color': '#333333'
})
palette = ['#27D3F5', '#6CF527', '#F5B027', '#F54927']
g = sns.lmplot(
data=df,
x='Volatility (%)',
y='Annual Return (%)',
hue='Sector',
col='Sector',
col_wrap=2,
height=3.5,
aspect=1.2,
palette=palette,
scatter_kws={'alpha': 0.7, 's': 55, 'edgecolor': 'white', 'linewidths': 0.5},
line_kws={'linewidth': 2.5},
ci=95
)
g.fig.set_facecolor('#0a0a0f')
for ax in g.axes.flat:
ax.set_facecolor('#0a0a0f')
for spine in ax.spines.values():
spine.set_color('#333333')
g.fig.suptitle('Risk-Return by Industry', fontsize=14, fontweight='bold', color='white', y=1.02)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Faceted Scatter Plot examples
☕