Plotting#
Data#
- plot_mean_sd(Y, ax=None, x=None, lw=3, linecolor=None, linestyle='-', facecolor=None, edgecolor=None, alpha=0.5, label=None, autoset_ylim=True, roi=None)[source]#
Plot mean continuum with standard deviation cloud.
- Parameters:
Y — (J,Q) numpy array
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
x — x positions [default: np.arange(Y.shape[1])]
lw — line width
linecolor — mean continuum line color
linestyle — mean continuum line style
facecolor — SD cloud face color
edgecolor — SD cloud edge color
alpha — SD cloud face alpha
label — mean continuum label (for matplotlib.pyplot.legend())
autoset_ylim — if True (default), set y limits to show all plotted elements
roi — (Q,) boolean region-of-interest vector (mean and SD plotted only where True)
- Returns:
(line, cloud)— mean line and SD cloud
- Example:
Mean and standard-deviation clouds of two conditions of the plantar arch angle dataset.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> ax = plt.gca() >>> line0, cloud0 = spm1d.plot.plot_mean_sd( y0, ax=ax, label='condition 0' ) >>> line1, cloud1 = spm1d.plot.plot_mean_sd( y1, ax=ax, linecolor='r', facecolor='r', label='condition 1' ) >>> legend = ax.legend() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_errorcloud(datum, sd, ax=None, x=None, facecolor=None, edgecolor=None, alpha=0.5, autoset_ylim=True)[source]#
Plot an error cloud around a datum continuum.
- Parameters:
datum — 1D list or numpy array
sd — 1D list or numpy array
ax — matplotlib.axes object
x — x positions [default: np.arange(datum.size)]
facecolor — SD cloud face color
edgecolor — SD cloud edge color
alpha — SD cloud face alpha
autoset_ylim — if True (default), set y limits to show all plotted elements
- Returns:
matplotlib.collections.PatchCollection object
- Example:
>>> import numpy as np >>> from matplotlib import pyplot
>>> a = np.random.rand(50) >>> b = np.random.rand(50) >>> spm1d.plot.plot_errorcloud(a, b) >>> pyplot.xlim(0, 50)
- plot_ci(ci, ax=None, x=None, linecolor=None, facecolor=None, edgecolor=None, alpha=0.5, autoset_ylim=True)[source]#
Plot a one-sample or difference 1D confidence region.
- Parameters:
ci — 1D one-sample or difference confidence interval
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
x — x positions [default: np.arange(Q)]
linecolor — mean continuum line color
facecolor — confidence cloud face color
edgecolor — confidence cloud edge color
alpha — confidence cloud face alpha
autoset_ylim — if True (default), set y limits to show all plotted elements
- Returns:
None
- Example:
A one-sample confidence region for one condition of the plantar arch angle dataset.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> ci = spm1d.stats.ci_onesample( y0, 0.05 ) >>> spm1d.plot.plot_ci( ci ) # equivalent to ci.plot() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_ci_0d(ci, ax=None, color='b', color_criterion='r', markersize=10, autoset_ylim=True)[source]#
Plot a one-sample (or paired-difference) confidence interval for 0D data.
- Parameters:
ci — 0D one-sample or difference confidence interval
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
color — interval (error bar) color
color_criterion — datum line (mu) color
markersize — marker size
autoset_ylim — if True (default), set y limits to show all plotted elements
- Returns:
None
- Example:
A one-sample confidence interval for the “morley” dataset from R.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> y = jd.R_Morley().y # (100,) array >>> ci = spm1d.stats.ci_onesample( y, 0.05 ) >>> spm1d.plot.plot_ci_0d( ci ) # equivalent to ci.plot() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_ci_multisample(ci, ax=None, x=None, linecolors=('k', 'b'), facecolors=('0.8', 'b'), edgecolors=('0.8', 'b'), color_criterion='r', alphas=(0.5, 0.5), autoset_ylim=True)[source]#
Plot a paired- or two-sample 1D confidence region (
datum='meanA').- Parameters:
ci — 1D confidence interval with
datum='meanA'ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
x — x positions [default: np.arange(Q)]
linecolors — mean continuum line colors as a 2-tuple (or one color for both)
facecolors — cloud face colors as a 2-tuple (or one color for both)
edgecolors — cloud edge colors as a 2-tuple (or one color for both)
color_criterion — second sample mean criterion color (dashed line)
alphas — cloud face alphas as a 2-tuple (or one value for both)
autoset_ylim — if True (default), set y limits to show all plotted elements
- Returns:
None
- Example:
A paired-sample confidence region centered on the first condition’s mean (
datum='meanA') for the plantar arch angle dataset.>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> ci = spm1d.stats.ci_pairedsample( y0, y1, 0.05, datum='meanA' ) >>> spm1d.plot.plot_ci_multisample( ci ) # equivalent to ci.plot() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_ci_multisample_0d(ci, ax=None, color='b', color_criterion='r', markersize=10, autoset_ylim=True)[source]#
Plot a paired- or two-sample 0D confidence interval (
datum='meanA').- Parameters:
ci — 0D confidence interval with
datum='meanA'ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
color — first sample interval (error bar) color
color_criterion — second sample mean color (marker, error bar and dashed line)
markersize — second sample mean marker size
autoset_ylim — if True (default), set y limits to show all plotted elements
- Returns:
None
- Example:
A paired-sample confidence interval centered on the first condition’s mean (
datum='meanA') for the “sleep” dataset from R.>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.R_SleepPairedTest() >>> y, A = dataset.y, dataset.x # (20,) arrays of responses and condition labels >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> ci = spm1d.stats.ci_pairedsample( y0, y1, 0.05, datum='meanA' ) >>> spm1d.plot.plot_ci_multisample_0d( ci ) # equivalent to ci.plot() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
SPM results#
- plot_spm(spm, ax=None, plot_ylabel=True, autoset_xlim=True, autoset_ylim=True, **kwdargs)[source]#
Plot an spm1d SPM object as a line.
- Parameters:
spm — spm1d SPM object
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
plot_ylabel — if True, add an
SPM{t}orSPM{F}y axis labelautoset_xlim — if True (default), set x axis limits to the domain
autoset_ylim — if True (default), set y limits to show all plotted elements
kwdargs — matplotlib.pyplot.plot keyword arguments
- Returns:
h — matplotlib.lines.Line2D object
- Example:
The t statistic continuum of a paired t test on the plantar arch angle dataset.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spm = spm1d.stats.ttest_paired( y0, y1 ) >>> line = spm1d.plot.plot_spm( spm ) # equivalent to line = spm.plot() >>> line.set_color( 'r' ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_spmi(spmi, ax=None, color=None, linestyle='-', marker='', facecolor=None, lw=2, plot_thresh=True, plot_ylabel=True, thresh_color=None, autoset_xlim=True, autoset_ylim=True, label=None, with_bars=False, bar_ax_loc=None, bar_color=None, bar_pvalues=False)[source]#
Plot an spm1d SPM inference object as a line.
- Parameters:
spmi — spm1d SPM inference object
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
color — raw SPM line color
linestyle — raw SPM line style
marker — raw SPM marker
facecolor — suprathreshold cluster face color
lw — raw SPM line width (default 2)
plot_thresh — if True, plot threshold lines
plot_ylabel — if True, add an
SPM{t}orSPM{F}y axis labelthresh_color — threshold line color
autoset_xlim — if True (default), set x axis limits to the domain
autoset_ylim — if True (default), set y limits to show all plotted elements
label — raw SPM legend label
with_bars — plot clusters as bars if True
bar_ax_loc — bar location: None (default),
'below'or'above'bar_color — bar color
bar_pvalues — if True, write cluster p values on bars
- Returns:
bar axes if bar_ax_loc is
'below'or'above', otherwise None
- Example:
Inference results of a paired t test on the plantar arch angle dataset with cluster bars below the panel.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> spm1d.plot.plot_spmi( spmi ) # equivalent to spmi.plot() >>> axb = spm1d.plot.plot_spmi( spmi, ax=plt.figure().gca(), with_bars=True, bar_ax_loc='below' ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_spmi_threshold_label(spmi, ax=None, lower=False, pos=None, autoset_ylim=True, **kwdargs)[source]#
Write the critical threshold value on its threshold line.
- Parameters:
spmi — spm1d SPM inference object
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
lower — if True, label the lower threshold (two-tailed inference)
pos — text location as a 2-tuple
autoset_ylim — if True (default), set y limits to show all plotted elements
kwdargs — matplotlib.pyplot.text keyword arguments
- Returns:
matplotlib.text.Text object
- Example:
Threshold label at a chosen position.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> spmi.plot() >>> label = spm1d.plot.plot_spmi_threshold_label( spmi, pos=(50, 3.0) ) # equivalent to spmi.plot_threshold_label( pos=(50, 3.0) ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_spmi_p_values(spmi, ax=None, size=8, offsets=None, offset_all_clusters=None, autoplace=None, autoset_ylim=True)[source]#
Plot SPM inference p values as text (if present).
- Parameters:
spmi — spm1d SPM inference object
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
size — font size
offsets — list of (x,y) offsets relative to cluster centroids
offset_all_clusters — (x,y) offset for all clusters relative to cluster centroids
autoplace — if True, avoid overlapping the SPM curve and other labels
autoset_ylim — if True (default), set y limits to show all plotted elements
- Returns:
list of matplotlib.text.Text objects (one per cluster)
- Example:
Cluster p values placed with an explicit offset from the cluster centroid.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> spmi.plot() >>> labels = spm1d.plot.plot_spmi_p_values( spmi, offsets=[(0, 0.2)] ) # one offset per cluster, equivalent to spmi.plot_p_values( offsets=[(0, 0.2)] ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_cluster_patches(spmi, ax=None, color=None, alpha=0.25, labels=None, zorder=0, **kwargs)[source]#
Plot suprathreshold clusters as vertical bands.
- Parameters:
spmi — inference SPM or list of inference SPMs (one color per element)
ax — axes [default: matplotlib.pyplot.gca()]
color — one color for all bands or one color per result
alpha — band transparency
labels — legend labels (one per result) [default: list labels or None]
zorder — plotting order (default 0: bands behind data)
- Returns:
list of patches per result
- Example:
Suprathreshold clusters as vertical bands behind the data.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> ax = plt.gca() >>> h0 = spm1d.plot.plot_mean_sd( y0, ax=ax ) >>> h1 = spm1d.plot.plot_mean_sd( y1, ax=ax, linecolor='r', facecolor='r' ) >>> patches = spm1d.plot.plot_cluster_patches( spmi, ax=ax ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_cluster_bars(spmi, ax=None, color=None, height=None, labels=None, pvalues=False, fontsize=8, tidy=True, transform=None, y=None, label_colors=None, **kwargs)[source]#
Plot suprathreshold clusters as horizontal bars (one row per result).
- Parameters:
spmi — inference SPM or list of inference SPMs (one row per element)
ax — axes [default: matplotlib.pyplot.gca()]
color — one color for all bars or one color per row
height — bar height [default: 0.35]
labels — y tick labels (one per row) [default: list labels if present]
pvalues — if True, write cluster p values above bars
fontsize — p value font size
tidy — if True (default), hide y ticks and top, left and right spines
transform, y — for plotting inside another plot
label_colors — dict mapping row label parts to colors (e.g.,
{'A0': 'C0', 'A1': 'C1'})
- Returns:
axes
- Example:
A strip of cluster bars beneath a plot of the data.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> fig, (ax0, ax1) = plt.subplots( 2, 1, sharex=True, gridspec_kw=dict( height_ratios=[9, 1] ) ) >>> h0 = spm1d.plot.plot_mean_sd( y0, ax=ax0 ) >>> h1 = spm1d.plot.plot_mean_sd( y1, ax=ax0, linecolor='r', facecolor='r' ) >>> ax = spm1d.plot.plot_cluster_bars( spmi, ax=ax1 ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_cluster_bars_colorsplit(spmi, ax=None, colors=None, height=None, labels=None, color_order_by_effect_sign=True, csign=None, pvalues=False, fontsize=8, tidy=True, **kwargs)[source]#
Plot post hoc clusters as horizontal bars split into compared group colors.
One row per pairwise comparison.
- Parameters:
spmi — post hoc list (
posthocoutput) or list of inference results with labels like"A0 - A1"ax — axes [default: matplotlib.pyplot.gca()]
colors — group colors as a dict (group name to color) or a sequence (order of first label appearance) [default: matplotlib’s color cycle]
height — bar height in row units (rows are one unit apart) [default: 0.5]
labels — y tick labels (one per row) [default: list labels]
color_order_by_effect_sign — if True (default), the group with the larger mean is on top; otherwise the first-named group is on top
csign — short alias of color_order_by_effect_sign
pvalues — if True, write cluster p values above bars
fontsize — p value font size
tidy — if True (default), hide top, left and right spines and y tick marks
kwargs — passed to
matplotlib.axes.Axes.broken_barh
- Returns:
Axes
- Example:
Post hoc bars beneath a plot of the group means.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.SpeedGRFcategoricalRM() >>> y, (A, S) = dataset.y, dataset.x.T >>> Fi = spm1d.stats.anova1rm( y, A, S ).inference( 0.05 ) >>> phi = Fi.posthoc( correction='bonf' ) >>> fig, (ax0, ax1) = plt.subplots( 2, 1, sharex=True, gridspec_kw=dict( height_ratios=[3, 1] ) ) >>> for a, color in zip( (0, 1, 2), ('b', 'k', 'r') ): ... h = spm1d.plot.plot_mean_sd( y[A == a], ax=ax0, linecolor=color, facecolor=color ) >>> ax = phi.plot_cluster_bars_colorsplit( ax=ax1, colors={'A0': 'b', 'A1': 'k', 'A2': 'r'} ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_cluster_barh(spmi, ax=None, loc=None, color=None, pvalues=False)[source]#
Attach a cluster bar strip to existing axes.
- Parameters:
spmi — inference SPM
ax — axes [default: matplotlib.pyplot.gca()]
loc — bar location: None (default),
'below'or'above'color — bar color
pvalues — if True, write cluster p values on bars
- Returns:
bar axes if loc is
'below'or'above', otherwise None
- Example:
Cluster bars attached below a plot of the data.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> ax = plt.gca() >>> h0 = spm1d.plot.plot_mean_sd( y0, ax=ax ) >>> h1 = spm1d.plot.plot_mean_sd( y1, ax=ax, linecolor='r', facecolor='r' ) >>> axb = spm1d.plot.plot_cluster_barh( spmi, ax=ax, loc='below', pvalues=True ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_effects(FF, style='means', colors=None, fig=None, figsize=None, bars=True, pvalues=True, legend=True, **kwargs)[source]#
One panel per ANOVA effect.
- Parameters:
FF — ANOVA result list
style —
'means'(default) or'differences'(see plot_effect)colors — one color per effect [default:
'C0','C1', …]fig — figure [default: new figure]
figsize — new figure size
bars, pvalues, legend — see plot_effect
- Returns:
(axs, axbs)— panel axes and bar axes
- Example:
One panel per effect of a simulated 2 x 3 ANOVA.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.SPM1D_ANOVA2_2x3() >>> y = dataset.y # (60,101) array >>> A, B = dataset.x.T # (60,) arrays >>> spmi = spm1d.stats.anova2( y, A, B ).inference( 0.05 ) >>> axs, axbs = spm1d.plot.plot_effects( spmi ) # equivalent to spmi.plot_effects() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_effect(spm, ax=None, style='means', color=None, bars=True, pvalues=True, legend=True, title=True, **kwargs)[source]#
Plot ANOVA effect data and clusters.
- Parameters:
spm — one ANOVA effect
ax — axes [default: matplotlib.pyplot.gca()]
style —
'means'(default) or'differences'color — cluster band, bar and title color
bars — if True (default), add a cluster bar strip beneath the panel (inference results only)
pvalues — write cluster p values above the bars
legend — plot the legend
title — panel title (True, a string or False)
kwargs — passed to line plots
- Returns:
(ax, axb)— panel axes and bar axes (None if no bars)
- Example:
The interaction panel of a simulated 2 x 3 ANOVA in the
differencesstyle.>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.SPM1D_ANOVA2_2x3() >>> y = dataset.y # (60,101) array >>> A, B = dataset.x.T # (60,) arrays >>> spmi = spm1d.stats.anova2( y, A, B ).inference( 0.05 ) >>> ax, axb = spm1d.plot.plot_effect( spmi[2], style='differences' ) # equivalent to spmi[2].plot_effect( style='differences' ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_effectsize(es, ax=None, **kwdargs)[source]#
Plot an effect size object as a bar (0D) or line (1D).
- Parameters:
es — spm1d effect size object
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
kwdargs — keyword arguments passed to bar (0D) or plot (1D)
- Returns:
Axes
- Example:
The effect size of a paired t test on the plantar arch angle dataset.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> es = spmi.effect_size() >>> ax = spm1d.plot.plot_effectsize( es ) # equivalent to es.plot() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_roi(roi, ax=None, facecolor=None, alpha=1, edgecolor=None, ylim=None)[source]#
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]".
Designs#
- plot_design(design, ax=None, term_labels=True, fontsize=9, cmap='gray')[source]#
Plot a design matrix as an image.
- Parameters:
design — spm1d design object (e.g.,
spm.design)ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
term_labels — label terms above their columns
fontsize — label font size
- Returns:
matplotlib.image.AxesImage
- Example:
The design matrix of a two-sample t test on two simulated groups of six responses.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.SimulatedTwoLocalMax() >>> y, A = dataset.y, dataset.x # (12,101) array and (12,) array >>> spm = spm1d.stats.ttest2( y[ A == 0 ], y[ A == 1 ] ) >>> image = spm1d.plot.plot_design( spm.design ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_spm_design(spm, ax=None, fontsize=10)[source]#
Plot the SPM design matrix using
plot_design(spm.design).- Parameters:
spm — spm1d SPM object before or after inference
ax — matplotlib.axes object [default: matplotlib.pyplot.gca()]
fontsize — label font size
- Returns:
matplotlib.image.AxesImage
- Example:
The design matrix of a two-sample t test on two simulated groups of six responses.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.SimulatedTwoLocalMax() >>> y, A = dataset.y, dataset.x # (12,101) array and (12,) array >>> spm = spm1d.stats.ttest2( y[ A == 0 ], y[ A == 1 ] ) >>> image = spm1d.plot.plot_spm_design( spm ) # equivalent to image = spm.plot_design() >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- plot_variance_components(QQ, ax=None, ncols=None, fontsize=9, cmap='gray')[source]#
Plot each design variance component as a small labeled J-by-J image.
- Parameters:
QQ — VarianceComponents object (
design.get_variance_model())ax — matplotlib.axes object whose figure receives the grid (the axes is removed) [default: new figure]
ncols — panels per row [default: approximately sqrt(count)]
fontsize — label font size (default 9)
cmap — matplotlib colormap name (default
'gray')
- Returns:
list of axes
- Example:
The two variance components (one variance per group) of a two-sample t test on two simulated groups of six responses.
>>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.SimulatedTwoLocalMax() >>> y, A = dataset.y, dataset.x # (12,101) array and (12,) array >>> spm = spm1d.stats.ttest2( y[ A == 0 ], y[ A == 1 ] ) >>> QQ = spm.design.get_variance_model() >>> axs = spm1d.plot.plot_variance_components( QQ ) >>> plt.show()
The example datasets require the jiku-data package:
pip install "spm1d[data]".
Validation#
Histograms of simulated test statistics from false positive rate validations.
- plot_validation(results, show=True)[source]#
Histogram of single-contrast validation values.
- Parameters:
results — validator SimulationResults
show — if True (default), call
matplotlib.pyplot.show
- Returns:
Axes (new figure)
- Example:
>>> import spm1d >>> validator = spm1d.util._val.val_ttest( 8, niter=200, progress_bar=False ) >>> ax = spm1d.plot.plot_validation( validator.results )
- plot_validation_multi(results, show=True)[source]#
One histogram per contrast for a multi-contrast validation.
- Parameters:
results — validator SimulationResultsMultiContrast
show — if True (default), call
matplotlib.pyplot.show
- Returns:
Array of axes (one per panel of a new figure)
- Example:
>>> import spm1d >>> validator = spm1d.util._val.val_anova2( [[5, 5], [5, 5]], [[1, 1], [1, 1]], niter=200, progress_bar=False ) >>> axs = spm1d.plot.plot_validation_multi( validator.results )