plot¶
plot.style¶
Style of the figures.
PlotStyle
dataclass
¶
PlotStyle(
data_color="#1f1f1f",
data_marker="o",
fit_color="#d55e00",
auc_color="#56b4e9",
extrapolation_color="#e69f00",
partial_color="#cc79a7",
terminal_marker="s",
alpha=0.2,
linewidth=1.5,
markersize=5.0,
marker_max_points=60,
cmap="viridis",
limit_color="tab:red",
pooled_color="tab:orange",
summary_color="tab:blue",
dose_color="gray",
peak_color="#009e73",
band_alpha=0.15,
annotation_fontsize="x-small",
)
Colors, markers and sizes shared by the figures of the package.
The default colors follow the palette of Okabe and Ito, which stays distinguishable for the common forms of color blindness: near-black data, a sky blue area, an orange extrapolation, a vermilion regression and a bluish green peak.
Attributes:
| Name | Type | Description |
|---|---|---|
data_color |
str
|
color of the data points and lines |
data_marker |
str
|
marker of the data points |
fit_color |
str
|
color of regression lines and fitted curves |
auc_color |
str
|
fill color of the area to the last measurable point |
extrapolation_color |
str
|
fill color of the extrapolated area |
partial_color |
str
|
fill color of a named partial area
( |
terminal_marker |
str
|
marker of the points of the terminal regression |
alpha |
float
|
transparency of filled areas |
linewidth |
float
|
width of lines |
markersize |
float
|
size of markers |
marker_max_points |
int
|
most points a curve may have and still be drawn with a marker per point; a longer curve (a simulation, a dense sampling) is drawn as a line alone, since its markers would merge into a band and hide the shape of the curve |
cmap |
str
|
colormap of the samples of a batch |
limit_color |
str
|
color of acceptance limits and interaction thresholds |
pooled_color |
str
|
color of pooled effects |
summary_color |
str
|
color of means and intervals drawn over individual points |
dose_color |
str
|
color of the dose time markers of a dosing protocol |
peak_color |
str
|
color of the marker and the guide lines of the peak
( |
band_alpha |
float
|
transparency of a confidence band |
annotation_fontsize |
str
|
font size of the annotations and the parameter box of the NCA panel |
plot.timecourse¶
Figures of timecourses: the curves of a batch and the mean curve of a group.
plot_timecourse
¶
plot_timecourse(
timecourses,
*,
log_y=False,
errorbars=True,
by=None,
facet=None,
max_legend=12,
ax=None,
axes=None,
style=DEFAULT_STYLE,
)
Plot one timecourse or every timecourse of a batch.
With by the curves are colored by group: every sample carrying the same
value of the coordinate gets the same color and the group contributes one
legend entry, instead of one color and one entry per sample. With facet
the batch is split into one panel per value of a coordinate, the colors
staying the same across the panels. A legend of more than max_legend
entries is left out, since it would cover the figure rather than explain
it.
A single curve whose protocol has more than one dose also gets one thin
dotted vertical line per dose time (style.dose_color) and, for an
infusion, the window from the dose time to the end of the infusion as a
shaded span; a batch draws no dose markers, since its curves may carry
different protocols (plot_mean_timecourse draws them for the group).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timecourses
|
Timecourse | Timecourses
|
the curve or the batch |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
log_y |
bool
|
logarithmic value axis; a curve without a positive value stays linear (logged at debug level) |
errorbars |
bool
|
draw |
by |
str | None
|
coordinate of the batch grouping the curves: one color and one legend entry per group, the sample label per curve by default |
facet |
str | None
|
coordinate of the batch drawn as one panel per value, a single panel by default |
max_legend |
int
|
most entries the legend of a panel may have |
ax |
Axes | None
|
axes to draw on, a new figure by default; a caller-supplied |
axes |
Sequence[Axes] | None
|
one axes per value of |
style |
PlotStyle
|
colors and markers |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
plot_mean_timecourse
¶
plot_mean_timecourse(
batch,
*,
by=None,
spread="sd",
individuals=True,
individual_alpha=0.25,
panels=("linear", "log"),
axes=None,
style=DEFAULT_STYLE,
)
The mean curve of every group with its spread, on a linear and a semi-log panel.
The concentration-time figure of a study report: the arithmetic mean of
the samples at every time point, the band \(\bar c \pm s\) of its spread
around it and, faint behind both, the individual curves. With by the
batch is split into groups (a dose level, a treatment, an arm) and every
group gets its own color; without it the whole batch is one group. The
reduction is Timecourses.groupby and Timecourses.mean, so the spread
is the scatter of the curves and not an uncertainty carried by them.
Both panels show the same curves, the second one on a logarithmic value axis with plain tick labels, and only the first one carries the legend. The dose markers of the first group are drawn on every panel: a dotted line per dose of a protocol of several doses, an infusion as the shaded window from the dose time to the end of the infusion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Timecourses
|
the batch, with at least one sample dimension. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
by |
str | None
|
coordinate of the batch grouping the curves (a sample dimension or a coordinate along one), one group by default. |
spread |
Literal['sd', 'se'] | None
|
the statistic of the band, the standard deviation ( |
individuals |
bool
|
draw the individual curves behind the mean. |
individual_alpha |
float
|
transparency of the individual curves. |
panels |
Sequence[str]
|
the panels, |
axes |
Sequence[Axes] | None
|
one axes per panel, a new figure by default. |
style |
PlotStyle
|
colors and markers. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
nominal_grid
¶
The nominal (scheduled) time of every point of a batch.
The variable nominal_time of the batch when it carries one
(Timecourses.from_arrays(nominal_time=...),
Timecourses.from_dataframe(nominal_time=...)), else the nearest entry of
nominal_times for every actual time, else the actual times themselves,
which is the right answer for data recorded on its schedule (a simulation,
a mean curve of a publication).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Timecourses
|
the batch |
required |
nominal_times
|
ArrayLike | None
|
the sampling schedule of the study, mapped to every
actual time by nearest neighbour; |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The nominal time of every sample and point, |
ndarray
|
|
on_nominal_times
¶
A copy of the batch whose samples sit on the shared grid of their nominal times.
Every point moves from the time it was taken at to the time it was scheduled for, and the batch gets the sorted union of those times as its grid: the samples of a study then share their time points and can be averaged, which is what the mean profile of a study report is taken on (ICH M13A 2.2.2.1). Two points of one sample with the same nominal time would land on the same place; the later one wins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Timecourses
|
the batch |
required |
nominal
|
ndarray
|
the nominal time of every sample and point, |
required |
Returns:
| Type | Description |
|---|---|
Timecourses
|
The batch on the nominal grid, the doses and the coordinates unchanged. |
plot_study_curves
¶
plot_study_curves(
batch,
*,
by=None,
nominal_times=None,
log_y_panels=True,
max_legend=12,
axes=None,
style=DEFAULT_STYLE,
)
The concentration-time figures of a study report, individuals and means.
ICH M13A (2024, 2.2.2.1) asks for the concentration-time profile of every
subject on a linear and on a semi-logarithmic scale, and for the mean
profile of every treatment on both scales as well, the individual figures
drawn against the actual sampling times and the mean figures against the
nominal ones: a mean over the subjects only exists on the schedule the
study sampled by. This function draws the four panels in one call, the
individual curves with plot_timecourse in the first row and the mean
curves with plot_mean_timecourse (mean, spread band and the individuals
behind it) in the second. A group keeps its color and its name over all
four panels: the legend of the individual row is drawn from the same group
labels as the one of the mean row (50 mg, which there carries the number
of subjects behind the mean as well).
The nominal times come from the variable nominal_time of the batch when
it carries one, else from nominal_times by nearest neighbour, else the
actual times are taken as nominal, which is the right answer for data
recorded on its schedule (nominal_grid, on_nominal_times).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Timecourses
|
the batch of the study, with at least one sample dimension |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
by |
str | None
|
coordinate of the batch grouping the curves (a treatment, an arm, a dose level), one group and one color by default; the groups keep their colors across the four panels |
nominal_times |
ArrayLike | None
|
the sampling schedule of the study, used when the batch
carries no |
log_y_panels |
bool
|
draw the two semi-logarithmic panels; |
max_legend |
int
|
most entries the legend of the figure may have; above it
none is drawn, as in |
axes |
Sequence[Axes] | None
|
the four axes to draw into (two with |
style |
PlotStyle
|
colors and markers |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the batch has no sample dimension. |
plot.nca¶
Diagnostic figures of the non-compartmental analysis.
parameter_rows
¶
The rows of the parameter table of plot_nca.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Mapping[str, float]
|
the parameter magnitudes. |
required |
units
|
Mapping[str, str] | None
|
the unit per parameter, |
required |
parameters
|
Sequence[str]
|
the parameters to list, in this order; a missing one is skipped. |
required |
ci_level
|
float
|
level of the interval of the half-life derived from the regression when the analysis reports none. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, str, str, str]]
|
One |
list[tuple[str, str, str, str]]
|
interval |
list[tuple[str, str, str, str]]
|
|
partial_window
¶
The interval of a named partial area in the times of an NCA panel.
The intervals of NCAOptions.partial_aucs are relative to the first dose
of the protocol, while a panel starts at the dose it analyses (the last one
of a multiple dose curve): the interval is shifted by the time between the
two doses, so that a named area of a multiple dose curve lands where the
analysis computed it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
NCAResult
|
the result of the analysis, which carries the intervals
( |
required |
timecourse
|
Timecourse
|
the curve the panel draws, for its dosing protocol |
required |
partial
|
str
|
name of the area |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
The |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the result carries no area of that name. |
draw_nca_panel
¶
draw_nca_panel(
timecourse,
values,
flags,
*,
log_y=False,
title=None,
legend=True,
annotate=True,
spread="sd",
ci_level=0.95,
units=None,
partial=None,
partial_range=None,
ax=None,
style=DEFAULT_STYLE,
)
Draw the NCA diagnostics of one curve into one axes.
The panel shows the data with their spread, the area to \(t_\mathrm{last}\)
(AUC(0-tlast)) or over the last dosing interval (AUC(0-tau) of a
multiple dose result), the extrapolated tail, the terminal regression line
with the points it used and its confidence band (_terminal_band), the
peak \(C_\mathrm{max}\)/\(t_\mathrm{max}\) with its guide lines, \(C_0\)
of a bolus, the named partial area partial over the area to
\(t_\mathrm{last}\), and the dose it analyses (an infusion as its window). With
annotate the areas, the peak, the last point, \(C_0\) and the regression
carry their values on the plot, the interval of the half-life from the uncertainty analysis
(thalf_ci_low/thalf_ci_high) or from the regression
(_thalf_interval); the table of every parameter is the third panel of
plot_nca.
The panel starts at the dose it analyses (the last one of a multiple dose curve), so only that dose falls inside it and the earlier doses of a protocol are not marked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timecourse
|
Timecourse
|
the curve (times relative to its dose) |
required |
values
|
Mapping[str, float]
|
parameter magnitudes of the curve, the uncertainty variables included when the result carries them |
required |
flags
|
list[str]
|
flag names of the curve |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
log_y |
bool
|
logarithmic value axis; a curve without a positive value stays linear (logged at debug level) |
title |
str | None
|
title, the label of the curve by default |
legend |
bool
|
draw the legend of the panel; |
annotate |
bool
|
write the values of the peak, the last point and the regression on the plot |
spread |
Literal['sd', 'se'] | None
|
the error bars of the data, |
ci_level |
float
|
level of the confidence band of the regression and of the interval of the half-life derived from it |
units |
Mapping[str, str] | None
|
the unit per parameter, for the annotations |
partial |
str | None
|
name of a named partial area of the result
( |
partial_range |
tuple[float, float] | None
|
the bounds |
ax |
Axes | None
|
axes to draw on, a new figure by default |
style |
PlotStyle
|
colors and markers |
Returns:
| Type | Description |
|---|---|
Axes
|
The axes the panel was drawn on. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
plot_nca
¶
plot_nca(
timecourse,
result,
*,
title=None,
annotate=True,
parameters=PANEL_PARAMETERS,
spread="sd",
ci_level=0.95,
partial=None,
axes=None,
style=DEFAULT_STYLE,
**indexers,
)
Linear and logarithmic panel of one curve with its NCA diagnostics and its parameters.
Both panels show the same curve (draw_nca_panel): the title of the
figure names the sample and its flags once, the two panels name the scale
they draw it on (linear, semi-logarithmic), and the legend is drawn
once, on the linear panel. A third, narrow panel lists the parameters
with their values, units and, where the result carries one, the interval
of the uncertainty analysis (x_ci_low/x_ci_high; the half-life falls
back to the interval of the regression), so that the figure reads as the
report of the analysis. axes of the caller take two entries for the two
curve panels alone, or three with the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timecourse
|
Timecourse
|
the curve |
required |
result
|
NCAResult
|
the result of its analysis (a batch result with |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
title |
str | None
|
title of the figure, |
annotate |
bool
|
write the values of the peak, the last point and the regression on the plot and add the parameter table |
parameters |
Sequence[str]
|
the parameters of the table, in this order (missing ones are skipped) |
spread |
Literal['sd', 'se'] | None
|
error bars of the data, |
ci_level |
float
|
level of the confidence band of the terminal regression and of the interval of the half-life derived from it |
partial |
str | None
|
name of a named partial area of the result
( |
axes |
Sequence[Axes] | None
|
the two axes to draw the linear and the logarithmic panel into, or three with the parameter table, a new figure by default; a figure of the caller keeps its own title, so the heading goes on the first panel instead |
style |
PlotStyle
|
colors and markers |
**indexers |
Any
|
coordinate labels selecting the sample of a batch result |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
plot_terminal_windows
¶
plot_terminal_windows(
timecourse,
result,
*,
options=None,
axes=None,
style=DEFAULT_STYLE,
**indexers,
)
The candidate windows of the terminal regression next to the chosen one.
The selection of the terminal phase is the judgement call a reviewer
questions, and every interactive tool shows it (the Slopes Selector of
Phoenix WinNonlin, the "Check lambda_z" tab of PKanalix). The figure has
two panels: the curve on a logarithmic value axis with the regression line,
the points it used and the chosen window between two dashed lines
(draw_nca_panel), and the adjusted \(R^2\) of every candidate window
against the time its first point was taken at, the chosen window marked and
the number of points of every window written above its marker. A window
starting later has fewer points, so the second panel reads from left
(many points) to right (three): where the curve is flat over several
windows the choice hardly matters, where it drops the terminal phase is
where the last points sit.
The result must carry the candidate windows, which the analysis keeps only when it is asked for them and only for a single curve:
# not executed
options = NCAOptions(terminal=TerminalPhase(keep_candidates=True))
result = nca_single(tc, options=options)
fig = plot_terminal_windows(tc, result, options=options)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timecourse
|
Timecourse
|
the curve |
required |
result
|
NCAResult
|
the result of its analysis, carrying |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
options |
NCAOptions | None
|
the options of the analysis; its
|
axes |
Sequence[Axes] | None
|
the two axes to draw the curve and the candidates into, a new figure by default |
style |
PlotStyle
|
colors and markers |
**indexers |
Any
|
coordinate labels selecting the sample of a batch result |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the result carries no candidate windows; a result of several samples carries none, since the analysis keeps them for a single curve only. |
plot_nca_grid
¶
plot_nca_grid(
timecourses,
result,
*,
ncols=3,
log_y=True,
annotate=False,
spread="sd",
ci_level=0.95,
partial=None,
axes=None,
style=DEFAULT_STYLE,
)
One NCA panel per sample of a batch, with one legend for the figure.
The title of a panel names the sample by its coordinates,
dose = 50 mg, individual = s1, with the unit of a coordinate which
carries one; the dose coordinate of a batch takes the dose unit of the
batch. The panels all draw the same artists, so the legend is drawn once:
on the figure when this function creates it, and into the first panel
when the caller supplies axes, whose figure keeps its own layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timecourses
|
Timecourses
|
the batch |
required |
result
|
NCAResult
|
its result |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
ncols |
int
|
panels per row, at most one per sample |
log_y |
bool
|
logarithmic value axes |
annotate |
bool
|
the values and the parameter box in every panel, off by default since the panels of a grid are small; the confidence band of the regression is drawn either way |
spread |
Literal['sd', 'se'] | None
|
error bars of the data, |
ci_level |
float
|
level of the confidence band of the terminal regression |
partial |
str | None
|
name of a named partial area of the result
( |
axes |
Sequence[Axes] | None
|
the |
style |
PlotStyle
|
colors and markers |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
plot_troughs
¶
The trough concentration of every dosing interval, the figure of steady state.
The trough of an interval (interval_ctrough, the value at its end) and,
when the analysis reports it, its minimum (interval_cmin) against the
time the trough was taken (x="time", the end of the interval
interval_end, which for a regular regimen is the time of the next dose)
or against the interval number (x="interval"). Steady state is where
the troughs stop rising.
Over a batch the samples are reduced to the mean of every interval with
its spread as error bars, per group when by names a coordinate; a
result of a single curve draws that curve's values. The title names the
statistic of the markers and the dimension it was taken over (mean ± sd
over individual), and stays empty where no reduction is drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
NCAResult
|
the result of a multiple dose analysis. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
by |
str | None
|
a sample dimension of the result or a coordinate along one, grouping the samples; one group by default. |
spread |
Literal['sd', 'se'] | None
|
error bars of the mean, the standard deviation ( |
x |
Literal['time', 'interval']
|
the x axis, the dose time of the interval or the interval number. |
ax |
Axes | None
|
axes to draw on, a new figure by default; a caller-supplied |
style |
PlotStyle
|
colors and markers. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the result has no interval parameters or no
|
plot_intervals
¶
Plot a per-interval parameter against the dosing interval.
Without indexers, one line per sample of the result, labelled with the
sample's coordinate values; with indexers selecting one sample, a single
line. Non-finite values (an incomplete interval) are masked so the line
breaks there instead of raising a matplotlib warning. The x axis carries
the integer interval numbers only, never a fractional tick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
NCAResult
|
the result of a multiple dose analysis |
required |
name
|
str
|
name of the per-interval variable ( |
'interval_auc'
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
ax |
Axes | None
|
axes to draw on, a new figure by default; a caller-supplied |
style |
PlotStyle
|
colors and markers |
**indexers |
Any
|
coordinate label per sample dimension selecting one sample |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the result has no interval parameters, or if |
plot_excretion
¶
plot_excretion(
result,
excretion,
*,
cumulative=True,
log_rate=True,
ax=None,
style=DEFAULT_STYLE,
)
Plot the excretion rate curve of a urine analysis and the amount recovered.
The figure a mass balance study is read from: the excretion rate \(\dot A_k\) of every collection against the midpoint \(\bar t_k\) of its interval on a logarithmic axis, with the terminal regression \(e^{b - \lambda_z t}\) over its window, and the cumulative amount recovered against the end of every collection on a second axis, which flattens out as the excretion stops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
NCAResult
|
the result of |
required |
excretion
|
Excretion
|
the collections the result was computed from, which carry the amount and the end of every interval |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
cumulative |
bool
|
whether the amount recovered is drawn on a second axis |
log_rate |
bool
|
whether the rate axis is logarithmic, where the terminal phase is a straight line |
ax |
Axes | None
|
axes to draw on, a new figure by default |
style |
PlotStyle
|
colors and markers |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the result carries no excretion rate curve (it is not
the result of |
plot_sparse
¶
Plot the mean curve of a sparse design with its area and the Bailer error.
The mean of the animals sampled at every nominal time with the standard
error \(s_j/\sqrt{n_j}\) of that mean as an error bar, auc_last shaded
under the polygon the linear trapezoid rule integrates (from the first
nominal time to the last measurable one, which is the window the estimator
covers, pkpdutils.nca.sparse.area_window), and the estimate with its
standard error and n_animals per time point written into the panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean_curve
|
Timecourse | Timecourses
|
the mean curve, a |
required |
result
|
NCAResult
|
the result of |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
log_y |
bool
|
whether the value axis is logarithmic |
ax |
Axes | None
|
axes to draw on, a new figure by default |
style |
PlotStyle
|
colors and markers |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the batch holds more than one sample, or if the result is not the one of a sparse analysis. |
plot.fit¶
Figures of fits: data and curve with residuals, goodness of fit, dose proportionality.
plot_fit
¶
plot_fit(
result,
*,
log_x=False,
log_y=False,
n_grid=200,
title=None,
axes=None,
style=DEFAULT_STYLE,
**indexers,
)
Data, fitted curve and weighted residuals of one sample.
The upper panel draws the data points (x_data, y_data, with error
bars from sd_data when the fit had sd), the fitted curve on a fine
grid between the smallest and the largest finite, plotted x (log-spaced
when log_x; the curve is skipped when fewer than two points remain),
and a title with the model name, the parameters (name = value +- se)
and the flags of the sample. The lower panel draws the weighted
residuals against x with a zero line.
The axes are labelled with the names the front end of the fit stored in
attrs["x_name"] and attrs["y_name"] (time and the substance for a
timecourse, the column names for a table), x and y without them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
FitResult
|
the fit. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
log_x |
bool
|
logarithmic x axis (and a log-spaced curve grid); a point
with |
log_y |
bool
|
logarithmic y axis; a point with |
n_grid |
int
|
number of points of the curve grid. |
title |
str | None
|
title, the model name by default; the parameters and the flags are appended. |
axes |
Sequence[Axes] | None
|
the two axes to draw the fit and the residual panel into, a new
figure by default; a caller-supplied pair is used as it is, so it
gives up the |
style |
PlotStyle
|
colors and markers. |
**indexers |
Any
|
coordinate label per sample dimension, none for a 0-D result. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure with the fit panel and the residual panel. |
plot_goodness_of_fit
¶
Predicted against observed values of every sample, with the identity line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
FitResult
|
the fit. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
log_x |
bool
|
logarithmic axis of the observed values; non-positive points are masked out to avoid a warning from the log scale. |
log_y |
bool
|
logarithmic axis of the predicted values, masked the same way. |
ax |
Axes | None
|
axes to draw on, a new figure by default. |
style |
PlotStyle
|
colors and markers. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
plot_dose_proportionality
¶
Log-log exposure against dose with the power fit and the acceptance bounds.
The axes are labelled with the names the front end of the fit stored in
attrs["x_name"] and attrs["y_name"] (the column names for
fit_table), x and y without them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
FitResult
|
fit of |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
test |
ProportionalityResult | None
|
the result of |
ax |
Axes | None
|
axes to draw on, a new figure by default. |
style |
PlotStyle
|
colors and markers. |
**indexers |
Any
|
coordinate label per sample dimension, none for a 0-D result. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
plot_bland_altman
¶
Bland-Altman plot of the predictions against the data of every sample.
The difference y_pred - y_data (the log ratio with log_ratio) against
the mean of both per point, with the mean difference and the limits of
agreement mean +- 1.96 sd as horizontal lines (Bland & Altman 1986).
log_ratio selects the statistic the figure shows and not only the scale
of an axis, which is why it is not one of the log_x/log_y keywords of
the other figures: it replaces the difference by the log ratio and draws
the mean on a logarithmic axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
FitResult
|
the fit. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
log_ratio |
bool
|
use the log ratio and the log mean; non-positive points are masked out. |
ax |
Axes | None
|
axes to draw on, a new figure by default. |
style |
PlotStyle
|
colors and markers. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
plot.parameters¶
Distribution of a parameter over the individuals, by group.
plot_parameters
¶
plot_parameters(
result,
name,
dim,
*,
by=None,
log_y=False,
scale=LOG,
ci_level=0.95,
ax=None,
style=DEFAULT_STYLE,
**indexers,
)
Strip and box plot of a parameter over a sample dimension, with the mean and its interval per group.
Every individual is a jittered point, every group a box plot, and the
geometric mean (scale=LOG) or the arithmetic mean with the t interval
of summarize at ci_level a marker with an error bar. The statistic
is computed from every finite value of the group, whatever the axis: a
group with a non-positive value has no geometric mean and gets the
arithmetic mean instead, drawn with a marker of its own (logged at debug
level).
With log_y=True the non-positive values are left out of both the strip
and the box, which are drawn from the same values, since a logarithmic
axis cannot show them; a group without a positive value keeps its tick
and nothing else, and a marker whose mean is not positive is left out.
Without a positive value in any group the axis stays linear and every
value is drawn.
The legend names the marker of every statistic once for the figure
(geometric mean [95 % CI], mean [...] with scale=Scale.LINEAR or
for the groups which fall back to it); the groups themselves are the
ticks of the x axis and stay out of it. It sits in the upper right corner
in room made above the data (legend_above_data), so it covers no point,
box or interval; the room is measured on the figure as laid out when the
function returns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ParameterResult
|
the result the parameter is taken from. |
required |
name
|
str
|
name of the parameter. |
required |
dim
|
str
|
the sample dimension of the individuals. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
by |
str | None
|
a coordinate along |
log_y |
bool
|
logarithmic y axis; without a positive value across every group the axis stays linear (logged at debug level). |
scale |
Scale | str
|
scale of the mean and its interval, the member or its string
( |
ci_level |
float
|
level of the interval. |
ax |
Axes | None
|
axes to draw on, a new figure by default; a caller-supplied |
style |
PlotStyle
|
colors and markers. |
**indexers |
Any
|
coordinate label per remaining sample dimension. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
plot.ratio¶
Ratios with their intervals against acceptance limits and interaction thresholds.
RatioLike
¶
plot_ratio
¶
plot_ratio(
ratios,
*,
limits=(0.8, 1.25),
thresholds=None,
annotate=True,
labels=None,
ax=None,
style=DEFAULT_STYLE,
)
Point estimates and intervals of ratios on a logarithmic axis, with limits and thresholds.
With annotate the rows carry their numbers, gmr [low, high], in a
column to the right of the intervals, as the table of a bioequivalence
report does; the axis is widened to hold the column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratios
|
Mapping[str, RatioLike] | BEResult
|
name to ratio, or a bioequivalence result (its parameters). |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
limits |
tuple[float, float] | None
|
acceptance limits drawn as dashed lines, |
thresholds |
DDIThresholds | None
|
interaction thresholds drawn as dotted lines with the
class names, |
annotate |
bool
|
write |
labels |
Mapping[str, str] | None
|
the tick label of a row per name, e.g.
|
ax |
Axes | None
|
axes to draw on, a new figure by default; a caller-supplied |
style |
PlotStyle
|
colors and markers. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
plot.meta¶
Forest plot of a meta-analysis.
plot_forest
¶
Forest plot: the effect of every study with its interval, the pooled effects as diamonds.
The marker area of a study is proportional to its random effects
weight. A LOG_RATIO analysis is shown as ratios on a logarithmic axis
(exp=None or True); the other kinds stay on their scale.
With annotate the rows carry their numbers in a column to the right of
the intervals, as a published forest plot does: estimate [low, high]
and, for a study, the random effects weight in percent; the axis is
widened to hold the column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
MetaResult
|
the meta-analysis. |
required |
Other Parameters:
| Name | Type | Description |
|---|---|---|
exp |
bool | None
|
exponentiate the effects; |
annotate |
bool
|
write the effect with its interval (and the weight of a study) beside every row. |
ax |
Axes | None
|
axes to draw on, a new figure by default; a caller-supplied |
style |
PlotStyle
|
colors and markers. |
Returns:
| Type | Description |
|---|---|
Figure
|
The figure. |