Hexbin Plot

Reaction Time Study

Psychology hexbin of stimulus intensity vs reaction time

Output
Reaction Time Study
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(2222)
intensity = np.random.uniform(10, 100, 5500)
reaction = 400 - 2 * intensity + np.random.exponential(50, 5500)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#0a0a12')
ax.set_facecolor('#0a0a12')

colors = ['#0a0a12', '#1a1a32', '#2a2a52', '#4a4a82', '#6a6ab2', '#8a8ae2', '#aaaaff', '#ccccff']
cmap = LinearSegmentedColormap.from_list('lavender', colors, N=256)

hb = ax.hexbin(intensity, reaction, gridsize=28, cmap=cmap, mincnt=1, edgecolors='none')

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.ax.set_facecolor('#0a0a12')
cbar.outline.set_edgecolor('#2a2a52')
cbar.ax.tick_params(colors='#8a8ae2', labelsize=9)
cbar.set_label('Trials', color='#8a8ae2', fontsize=10)

ax.set_xlabel('Stimulus Intensity (%)', color='#8a8ae2', fontsize=11)
ax.set_ylabel('Reaction Time (ms)', color='#8a8ae2', fontsize=11)
ax.tick_params(colors='#8a8ae2', labelsize=10)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support