psynlig.common¶
A module defining common methods.
- psynlig.common._get_text_boxes(axi, texts)[source]¶
Get bounding boxes for the givens text elements.
- Parameters
axi (object like
matplotlib.axes.Axes
) – The axis the text boxes reside in.texts (list of objects like
matplotlib.text.Text
) – The text boxes we attempt to jiggle around.
- Returns
boxes (list of objects like
shapely.geometry.polygon.Polygon
) – Polygons representing the bounding boxes.
- psynlig.common.add_trendline(axi, xdata, ydata, **kwargs)[source]¶
Add a trendline to the given axes.
- Parameters
axi (object like
matplotlib.axes.Axes
) – The axis to add the trendline to.xdata (object like
pandas.core.series.Series
) – The x-values to add a trendline for.ydata (object like
pandas.core.series.Series
) – The y-values to add a trendline for.**kwargs (dict, optional) – Additional arguments passed to the plotting method.
- Returns
line (object like
matplotlib.lines.Line2D
) – The created line.
- psynlig.common.add_xy_line(axi, **kwargs)[source]¶
Add a y=x line to the given axes.
- Parameters
axi (object like
matplotlib.axes.Axes
) – The axis to add the y=x line to.**kwargs (dict, optional) – Additional arguments passed to the plotting method.
- Returns
line (object like
matplotlib.lines.Line2D
) – The created y=x line.
- psynlig.common.create_fig_and_axes(nplots, nrows=None, ncols=None, **kwargs)[source]¶
Create a set of figures and axes.
The number of plots per figure is limited by the specified rows and columns. The plots will be created with constrained layout unless this is explicitly set to False.
- Parameters
nplots (integer) – The total number of plots to make.
nrows (integer) – The number of rows to create in each plot.
ncols (integer) – The number of columns to create in each plot.
kwargs (dict) – Extra settings for creating the figure(s).
- Returns
figures (list of objects like
matplotlib.figure.Figure
) – The figures created here.axes (list of objects like
matplotlib.axes.Axes
) – The axes created here.
- psynlig.common.find_axis_intersection(axi, xcoeff, ycoeff)[source]¶
Find intersection between a line and the axis bounds.
- Parameters
axi (object like
matplotlib.axes.Axes
) – The axis we will find intersections in,xcoeff (float) – The x-value for the line we are to extend.
ycoeff (float) – The y-value for the line we are to extend.
- Returns
xend (float) – The x ending point for the extended line.
yend (float) – The y ending point for the extended line.
- psynlig.common.get_rsquared(yval, yre)[source]¶
Obtain the coefficient of determination (R^2).
- Parameters
yval (numpy.array) – The y-values used in the fitting.
yre (numpy.array) – The estimated y-values from the fitting.
- Returns
rsq (float) – The estimated value of R^2.
Notes
- psynlig.common.get_selector(components, select_components, combi)[source]¶
Get a selector for components.
This is helper method in case we select a subset of components, or wish to plot for all combinations.
- Parameters
components (integer) – The number of components we are selecting from,
select_components (iterable or None) – The items we are to pick. If this is None, we select all combinations.
combi (integer) – The number of combinations of the components we are selecting, in the case we are to generate them here.
- Returns
selector (generator) – A generator which gives the indices for the components we are to select.
- psynlig.common.get_text_settings(settings, default=None)[source]¶
Get text settings for loadings.
- Parameters
settings (dict or None) – The provided settings.
default (dict or None,) – The default settings. In case None is given, we use hard-coded default settings given here.
- Returns
text_settings (dict) – A dict containing the text settings.
outline_settings (dict) – A dict containing settings for creating a stroke outline.
- psynlig.common.iqr_outlier(data, variables)[source]¶
Locate outliers by computing the interquartile range.
- Returns
out_of_bounds (object like
pandas.core.frame.DataFrame
)outliers (dict of integer) – For each variable, these are the indexes of possible outliers.
(upper, lower) (tuple of objects like
pandas.core.series.Series
) – These are the bounds for outlier detection.
- psynlig.common.jiggle_text(axi, texts, maxiter=1000)[source]¶
Attempt to jiggle text around so that they do not overlap.
- Parameters
axi (object like
matplotlib.axes.Axes
) – The axis the text boxes reside in.texts (list of objects like
matplotlib.text.Text
) – The text boxes we attempt to jiggle around.maxiter (integer, optional) – The maximum number of attempts we make to jiggle the text around.
- psynlig.common.set_origin_axes(axi, xlabel, ylabel, **kwargs)[source]¶
Move the x and y-axes of a plot to the origin.
- Parameters
axi (object like
matplotlib.axes.Axes
) – The axis to modify.xlabel (string) – The label to use for the x-axis.
ylabel (string) – The label to use for the y-axis.
kwargs (dict, optional) – Additional font settings for the axis labels.
- psynlig.common.set_up_fig_and_axis(fig, axi)[source]¶
Create a figure and axis if needed.
- Parameters
fig (object like
matplotlib.figure.Figure
) – The current figure. If None is given, we create a new one here.axi (object like
matplotlib.axes.Axes
) – The current axis. If None is given, we create a new one here.
- Returns
fig (object like
matplotlib.figure.Figure
) – The figure created here, if any. If no figure was created, this is just the figure we got as a parameter.axi (object like
matplotlib.axes.Axes
) – The axis created here. If no axis was created, this is just the figure we got as a parameter.