lir.plotting package
- class lir.plotting.Canvas(ax: Axes)[source]
Bases:
objectRepresentation of an empty canvas, to be used in plotting multiple visualizations.
- Parameters:
ax (Axes) – Matplotlib axes instance used by wrapped plotting methods.
- ax
Matplotlib axes instance used by wrapped plotting methods.
- Type:
Axes
- ece
Method to plot expected calibration error (ECE) on this canvas.
- Type:
Callable[…, Any]
- lr_histogram
Method to plot a histogram of likelihood ratios on this canvas.
- Type:
Callable[…, Any]
- nbe
Method to plot the Bayes error rate (NBE) on this canvas.
- Type:
Callable[…, Any]
- pav
Method to plot the Pool Adjacent Violators (PAV) transformation on this canvas.
- Type:
Callable[…, Any]
- score_distribution
Method to plot the distribution of scores on this canvas.
- Type:
Callable[…, Any]
- tippett
Method to plot Tippett plots on this canvas.
- Type:
Callable[…, Any]
- llr_interval
Method to plot LLR intervals on this canvas.
- Type:
Callable[…, Any]
- lir.plotting.axes(savefig: PathLike | str | None = None, show: bool | None = None) Iterator[Canvas][source]
Create a plotting context.
- Parameters:
savefig (PathLike | str | None, optional) – File path to save the figure on context exit.
show (bool | None, optional) – Whether to display the figure on context exit.
- Returns:
Iterator yielding a Canvas instance for plotting.
- Return type:
Iterator[Canvas]
Examples
with axes() as ax: ax.pav(llrdata)
- lir.plotting.histogram(ax: Axes, x: ndarray, labels: ndarray | None, bins: int = 20, weighted: bool = True, x_label: str = '') None[source]
Plot x as a histogram, optionally separated by class labels.
This class is mainly used as a helper for plotting LLR or score histograms.
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
x (np.ndarray) – The array of values to plot.
labels (np.ndarray | None) – The array of class labels for each value in x.
bins (int) – Number of bins to divide scores into (default: 20).
weighted (bool) – If y-axis should be weighted for frequency within each class (default: True).
x_label (str) – Label for the x-axis (default: ‘’).
- lir.plotting.llr_interval(ax: Axes, llrdata: LLRData) None[source]
Plot the LRs on the x-axis, with the relative interval score on the y-axis.
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
llrdata (LLRData) – The LLRData object containing the likelihood ratios and interval scores.
- lir.plotting.lr_histogram(ax: Axes, llrdata: LLRData, bins: int = 20, weighted: bool = True) None[source]
Plot the 10log LRs.
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
llrdata (LLRData) – The LLRData object containing likelihood ratios and labels.
bins (int) – Number of bins to divide scores into (default: 20).
weighted (bool) – If y-axis should be weighted for frequency within each class (default: True).
- lir.plotting.pav(ax: Axes, llrdata: LLRData, add_misleading: int = 0, show_scatter: bool = True) None[source]
Generate a plot of pre-calibrated versus post-calibrated LRs using Pool Adjacent Violators (PAV).
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
llrdata (LLRData) – The LLRData object containing likelihood ratios and labels.
add_misleading (int, optional) – Number of misleading evidence points to add on both sides (default:
0).show_scatter (bool, optional) – If True, show individual LRs (default:
True).
- lir.plotting.savefig(path: str) _GeneratorContextManager[Canvas][source]
Create a plotting context and write the figure to a file when the context exits.
- Parameters:
path (str) – Path to the output file. The figure is written as a PNG image.
- Returns:
Context manager yielding a Canvas and saving on exit.
- Return type:
_GeneratorContextManager[Canvas]
Examples
with savefig(path) as ax: ax.pav(llrdata)
A call to
savefig()is equivalent to callingaxes()withsavefig=path.
- lir.plotting.score_distribution(ax: Axes, llrdata: LLRData, bins: int = 20, weighted: bool = True) None[source]
Plot the distributions of scores calculated by the (fitted) LR system.
If weighted is True, the y-axis represents the probability density within the class. Otherwise, they-axis shows the number of instances.
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
llrdata (LLRData) – The LLRData object containing the scores and labels. Must have scores available.
bins (int) – Number of bins to divide scores into (default: 20).
weighted (bool) – If y-axis should be the probability density within each class, instead of counts (default: True).
- lir.plotting.score_to_llr(ax: Axes, llrdata: LLRData) None[source]
Plot intermediate scores vs final LLRs, colored by hypothesis.
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
llrdata (LLRData) – The LLRData object containing likelihood ratios and labels. Must have scores available. If labels are present, use them in the plots to color the points by hypothesis. If not, plot all points in the same color.
- lir.plotting.show() _GeneratorContextManager[Canvas][source]
Create a plotting context and show the figure when the context exits.
- Returns:
Context manager yielding a Canvas and showing the figure on exit.
- Return type:
_GeneratorContextManager[Canvas]
Examples
with show() as ax: ax.pav(llrdata)
A call to
show()is equivalent to callingaxes()withshow=True.
- lir.plotting.tippett(ax: Axes, llrdata: LLRData, plot_type: int = 1) None[source]
Plot empirical cumulative distribution functions of same-source and different-sources LRs.
- Parameters:
ax (Axes) – The matplotlib axes object to plot on.
llrdata (LLRData) – The LLRData object containing likelihood ratios and labels.
plot_type (int) – Must be either 1 or 2 (default: 1). In type 1 both curves show proportion of lrs greater than or equal to the x-axis value, while in type 2 the curve for same-source shows the proportion of lrs smaller than or equal to the x-axis value.