Faceted Scatter Plot
Network Latency by Protocol
Bandwidth-latency tradeoff across communication protocols
Output
Python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
np.random.seed(333)
protocols = ['TCP', 'UDP', 'QUIC', 'WebSocket']
data = []
for proto in protocols:
n = 42
bandwidth = np.random.uniform(10, 1000, n)
latency_base = {'TCP': 50, 'UDP': 20, 'QUIC': 30, 'WebSocket': 45}
latency = latency_base[proto] + 200 / np.sqrt(bandwidth) + np.random.normal(0, 8, n)
for b, l in zip(bandwidth, latency):
data.append({'Bandwidth (Mbps)': b, 'Latency (ms)': l, 'Protocol': proto})
df = pd.DataFrame(data)
plt.style.use('dark_background')
sns.set_style("darkgrid", {
'axes.facecolor': '#0a0a0f',
'figure.facecolor': '#0a0a0f',
'grid.color': '#333333'
})
palette = ['#F5276C', '#27F5B0', '#F5B027', '#4927F5']
g = sns.lmplot(
data=df,
x='Bandwidth (Mbps)',
y='Latency (ms)',
hue='Protocol',
col='Protocol',
col_wrap=2,
height=3.5,
aspect=1.2,
palette=palette,
scatter_kws={'alpha': 0.75, 's': 50, 'edgecolor': 'white', 'linewidths': 0.4},
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('Network Protocol Performance', fontsize=14, fontweight='bold', color='white', y=1.02)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Faceted Scatter Plot examples
☕