2D Histogram

Neural Network Activations

Layer-to-layer activation density with tanh non-linearity

Output
Neural Network Activations
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Neural network layer activations
np.random.seed(42)
n_samples = 10000

# Layer 1 and Layer 2 activations (ReLU-like distribution)
layer1 = np.maximum(0, np.random.normal(0.5, 0.8, n_samples))
layer1 = np.clip(layer1, 0, 3)

layer2 = np.maximum(0, 0.6 * layer1 + np.random.normal(0.3, 0.5, n_samples))
layer2 = np.clip(layer2, 0, 3)

# AI/ML dark theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#08080c')
ax.set_facecolor('#08080c')

# Custom colormap - neural network cyan
colors = ['#08080c', '#0a1020', '#0a2040', '#1a4060', '#2a6080', 
          '#3a80a0', '#4aa0c0', '#6ac0e0', '#8ae0ff', '#aaf0ff', '#d0ffff']
cmap = LinearSegmentedColormap.from_list('neural', colors, N=256)

# 2D histogram
h = ax.hist2d(layer1, layer2, bins=50, cmap=cmap, cmin=1)

# Dead neuron zone
ax.axhspan(0, 0.1, alpha=0.2, color='#ff6b6b', label='Dead Neurons')
ax.axvspan(0, 0.1, alpha=0.2, color='#ff6b6b')

# Saturation line
ax.plot([0, 3], [0, 2.5], '--', color='#4aa0c0', linewidth=1.5, alpha=0.6, label='Linear Response')

# Styled colorbar
cbar = plt.colorbar(h[3], ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#08080c')
cbar.set_label('Activation Count', fontsize=11, color='#a0e0f0', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#a0e0f0')
cbar.outline.set_edgecolor('#2a4050')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#a0e0f0', fontsize=9)

# Labels
ax.set_xlabel('Layer 1 Activation', fontsize=13, color='#a0e0f0', fontweight='600', labelpad=10)
ax.set_ylabel('Layer 2 Activation', fontsize=13, color='#a0e0f0', fontweight='600', labelpad=10)
ax.set_title('Neural Network Activation Patterns', fontsize=16, color='white', fontweight='bold', pad=20)

ax.tick_params(colors='#80c0d0', labelsize=10, length=0)
for spine in ax.spines.values():
    spine.set_visible(False)

ax.legend(loc='upper left', fontsize=9, facecolor='#1a2030', edgecolor='#2a4050', labelcolor='#a0e0f0')
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support