Event Plots with eventplot(D)ΒΆ

An event plot draws short parallel lines (tick marks) at specified positions along an axis, with each row of events displayed at a different offset. The Axes.eventplot() method takes a list of arrays, where each array contains the positions of events in one series, and renders them as vertically (or horizontally) stacked rows of tick marks.

Why this matters for data science: Event plots (also called raster plots or spike trains) are the standard visualization for point process data – events that occur at specific times or positions. They are widely used in neuroscience (visualizing neural spike trains), system monitoring (server request times), genomics (mutation positions along a chromosome), and log analysis (error occurrence times). The orientation="vertical" parameter draws events as vertical lines, while lineoffsets=x positions each series at the specified x-coordinates. The example generates data from a gamma distribution (np.random.gamma(4)), which produces positive, right-skewed values typical of inter-event intervals in real-world processes. Each row contains 50 events, and the clustering patterns visible in the plot reflect the underlying distribution’s shape.

import matplotlib.pyplot as plt
import numpy as np

plt.style.use('_mpl-gallery')

# make data:
np.random.seed(1)
x = [2, 4, 6]
D = np.random.gamma(4, size=(3, 50))

# plot:
fig, ax = plt.subplots()

ax.eventplot(D, orientation="vertical", lineoffsets=x, linewidth=0.75)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
       ylim=(0, 8), yticks=np.arange(1, 8))

plt.show()