Plotting Utilities#
Utility functions for the plotting commands.
- lyscripts.plots.floor_at_decimal(value: float, decimal: int) float[source]#
Compute the floor of
valuefor the specifieddecimal.Essentially the distance to the right of the decimal point. May be negative.
- lyscripts.plots.ceil_at_decimal(value: float, decimal: int) float[source]#
Compute the ceiling of
valuefor the specifieddecimal.Analog to
floor_at_decimal(), this is the distance to the right of the decimal point. May be negative.
- lyscripts.plots.floor_to_step(value: float, step: float) float[source]#
Compute next value on ladder of stepsize
stepstill belowvalue.
- lyscripts.plots.ceil_to_step(value: float, step: float) float[source]#
Compute next value on ladder of stepsize
stepstill abovevalue.
- lyscripts.plots.clean_and_check(filename: str | Path) Path[source]#
Check if file with
filenameexists.If not, raise error, otherwise return cleaned
PosixPath.
- pydantic model lyscripts.plots.AbstractDistribution[source]#
Abstract class for distributions that should be plotted.
Show JSON schema
{ "title": "AbstractDistribution", "description": "Abstract class for distributions that should be plotted.", "type": "object", "properties": { "scale": { "default": 100.0, "title": "Scale", "type": "number" }, "offset": { "default": 0.0, "title": "Offset", "type": "number" }, "kwargs": { "additionalProperties": true, "title": "Kwargs", "type": "object" } } }
- abstract left_percentile(percent: float) float[source]#
Compute the point where
percentof the values are to the left.
- pydantic model lyscripts.plots.Histogram[source]#
Class containing data for plotting a histogram.
Show JSON schema
{ "title": "Histogram", "description": "Class containing data for plotting a histogram.", "type": "object", "properties": { "scale": { "default": 100.0, "title": "Scale", "type": "number" }, "offset": { "default": 0.0, "title": "Offset", "type": "number" }, "kwargs": { "additionalProperties": true, "title": "Kwargs", "type": "object" }, "raw_values": { "items": { "type": "number" }, "title": "Raw Values", "type": "array" } }, "required": [ "raw_values" ] }
- classmethod from_hdf5(filename: str | Path, dataname: str, scale: float = 100.0, offset: float = 0.0, **kwargs) Histogram[source]#
Create a histogram from an HDF5 file.
- left_percentile(percent: float) float[source]#
Compute the point where percent of the values are to the left.
- pydantic model lyscripts.plots.BetaPosterior[source]#
Class for storing plot configs for a Beta posterior.
Show JSON schema
{ "title": "BetaPosterior", "description": "Class for storing plot configs for a Beta posterior.", "type": "object", "properties": { "scale": { "default": 100.0, "title": "Scale", "type": "number" }, "offset": { "default": 0.0, "title": "Offset", "type": "number" }, "kwargs": { "additionalProperties": true, "title": "Kwargs", "type": "object" }, "num_success": { "title": "Num Success", "type": "integer" }, "num_total": { "title": "Num Total", "type": "integer" } }, "required": [ "num_success", "num_total" ] }
- classmethod from_hdf5(filename: str | Path, dataname: str, scale: float = 100.0, offset: float = 0.0, **kwargs) BetaPosterior[source]#
Initialize data container for Beta posteriors from HDF5 file.
- property num_fail#
Return the number of failures, i.e. the totals minus the successes.
- lyscripts.plots.get_size(width='single', unit='cm', ratio='golden')[source]#
Return a tuple of figure sizes in inches.
This is provided as the
matplotlibkeyword argumentfigsizeexpects it. This figure size is computed from awidth, in theunitof centimeters by default, and aratiowhich is set to the golden ratio by default.>>> get_size(width="single", ratio="golden") (3.937007874015748, 2.4332557935820445) >>> get_size(width="full", ratio=2.) (6.299212598425196, 3.149606299212598) >>> get_size(width=10., ratio=1.) (3.937007874015748, 3.937007874015748) >>> get_size(width=5, unit="inches", ratio=2./3.) (5, 7.5)
- lyscripts.plots.get_label(attrs: Mapping) str[source]#
Extract label of a histogram from the HDF5
attrsobject of the dataset.
- lyscripts.plots.get_xlims(contents: AbstractDistributionT, percent_lims: tuple[float] = (10.0, 10.0)) tuple[float][source]#
Get the x-axis limits for a plot containing multiple distribution.
Compute the
xlimsof a plot containing histograms and probability density functions by considering their smallest and largest percentiles.
- lyscripts.plots.draw(axes: MPLAxes, contents: list[AbstractDistribution], percent_lims: tuple[float, float] = (10.0, 10.0), xlims: tuple[float] | None = None, hist_kwargs: dict[str, Any] | None = None, plot_kwargs: dict[str, Any] | None = None) MPLAxes[source]#
Draw histograms and Beta posterior from
contentsintoaxes.The limits of the x-axis is computed to be the smallest and largest left and right percentile of all provided
contentsrespectively via thepercent_limstuple.The
hist_kwargsdefine general settings that will be applied to all histograms. One additional key'nbins'may be used to adjust only the numbers, not the spacing of the histogram bins. Similarly,plot_kwargsadjusts the default settings for the Beta posteriors.Both these keyword arguments can be overwritten by what the individual
contentshave defined.
- lyscripts.plots.split_legends(axes: MPLAxes, titles: list[str], locs: list[tuple[float, float]], **kwargs) None[source]#
Separate labels in
axesinto separate legends withtitlesatlocs.