Hexbin Plot

Heart Rate Recovery

Medical hexbin showing peak heart rate vs recovery rate

Output
Heart Rate Recovery
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(333)
peak_hr = np.random.normal(170, 15, 5000)
recovery_rate = 30 + 0.1 * peak_hr + np.random.normal(0, 8, 5000)

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

colors = ['#fce7f3', '#fbcfe8', '#f9a8d4', '#f472b6', '#ec4899', '#db2777', '#be185d', '#9d174d']
cmap = LinearSegmentedColormap.from_list('pink', colors, N=256)

hb = ax.hexbin(peak_hr, recovery_rate, gridsize=25, cmap=cmap, mincnt=1, edgecolors='white', linewidths=0.3)

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.outline.set_edgecolor('#fbcfe8')
cbar.ax.tick_params(colors='#be185d', labelsize=9)
cbar.set_label('Patients', color='#be185d', fontsize=10)

ax.set_xlabel('Peak Heart Rate (bpm)', color='#be185d', fontsize=11)
ax.set_ylabel('Recovery Rate (bpm/min)', color='#be185d', fontsize=11)
ax.tick_params(colors='#be185d', labelsize=10)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#fbcfe8')
ax.spines['bottom'].set_color('#fbcfe8')

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support