Cycle Duration Histogram#

Visualize the distribution of gastric cycle durations using plot_cycle_histogram. The normogastric range (default 15–30 s) is marked with dashed lines, and the percentage of normogastric cycles is shown in the title.

import matplotlib.pyplot as plt

import gastropy as gp

plt.rcParams["figure.dpi"] = 100
plt.rcParams["figure.facecolor"] = "white"
# Load and process
egg = gp.load_egg()
best_idx, _, _, _ = gp.select_best_channel(egg["signal"], egg["sfreq"])
_, info = gp.egg_process(egg["signal"][best_idx], egg["sfreq"])
durations = info["cycle_durations_s"]
print(f"{len(durations)} cycles detected")
37 cycles detected

Default Normogastric Range (15–30 s)#

fig, ax = gp.plot_cycle_histogram(durations)
plt.show()
../_images/bb77440b990da63b93256d443471176c91eb04bb45aa9f203a226ac1ee3effc3.png

Custom Normogastric Range#

Some studies use a narrower range (e.g., 17–25 s for ~2.4–3.5 cpm). Pass normo_range to adjust the boundary lines and percentage.

fig, ax = gp.plot_cycle_histogram(durations, normo_range=(17.0, 25.0))
ax.set_title(ax.get_title().replace("normogastric", "normogastric (strict)"))
plt.show()
../_images/94a622d9ee135bb27aaaa7d59f618fc73a5ccf7e1686d4b62b474f4f5531028d.png

Side-by-Side Comparison#

Pass an ax to embed the histogram in a custom figure layout.

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4))
gp.plot_cycle_histogram(durations, normo_range=(15.0, 30.0), ax=ax1)
ax1.set_title("Standard (15–30 s)")
gp.plot_cycle_histogram(durations, normo_range=(17.0, 25.0), ax=ax2)
ax2.set_title("Strict (17–25 s)")
fig.tight_layout()
plt.show()
../_images/73a528a132e0cf884a801f6a9a6f0bd0058e3e2eb163adc29e94562a6c8ae013.png

See also: Quality Assessment, EGG Processing Tutorial