Source code for spm1d.plot._roi
# Copyright (C) 2026 Todd Pataky
from . import _style
[docs]
def plot_roi(roi, ax=None, facecolor=None, alpha=1, edgecolor=None, ylim=None):
'''
Shade a region of interest.
:Parameters:
- *roi* --- (Q,) boolean region array
- *ax* --- axes [default: matplotlib.pyplot.gca()]
- *facecolor* --- fill color [default: light gray]
- *alpha* --- fill transparency [default: 1]
- *edgecolor* --- edge color [default: panel color]
- *ylim* --- (y0, y1) rectangle vertical extent [default: current y limits]
:Returns:
- None
:Example:
A region of interest beneath a plot of the data.
>>> import numpy as np
>>> import spm1d
>>> import jikudata as jd
>>> from matplotlib import pyplot as plt
>>> y = jd.SimulatedPataky2015b().y # (10,101) array
>>> roi = np.zeros( 101, dtype=bool )
>>> roi[20:60] = True
>>> ax = plt.axes()
>>> h = spm1d.plot.plot_mean_sd( y, ax=ax )
>>> spm1d.plot.plot_roi( roi, ax=ax )
>>> plt.show()
The example datasets require the jiku-data package:
``pip install "spm1d[data]"``.
'''
facecolor, edgecolor = _style.gray(0.7, facecolor), _style.panel(edgecolor)
from . _plotters import DataPlotter
plotter = DataPlotter(ax)
plotter.plot_roi(roi, ylim=ylim, facecolor=facecolor, edgecolor=edgecolor, alpha=alpha)