fastplotlib.utils#
- calculate_figure_shape(n_subplots)[source]#
Returns
(n_rows, n_cols)
from given number of subplotsn_subplots
- make_colors(n_colors, cmap, alpha=1.0)[source]#
Get colors from a colormap. The returned colors are uniformly spaced, except for qualitative colormaps where they are returned subsequently.
- make_colors_dict(labels, cmap, **kwargs)[source]#
Get a dict for mapping labels onto colors.
- Parameters:
labels (Sequence[Any]) – labels for creating a colormap. Order is maintained if it is a list of unique elements.
cmap (str) – name of colormap
**kwargs – passed to make_colors()
- Returns:
keys are labels, values are colors
- Return type:
OrderedDict
Examples
from fastplotlib.utils import get_colors_dict labels = ["l1", "l2", "l3"] labels_cmap = get_colors_dict(labels, cmap="tab10") # illustration of what the `labels_cmap` dict would look like: # keep in mind that the tab10 cmap was chosen here { "l1": <RGBA array for the blue 'tab10' color>, "l2": <RGBA array for the orange 'tab10' color>, "l3": <RGBA array for the green 'tab10' color>, } # another example with a non-qualitative cmap labels_cmap_seismic = get_colors_dict(labels, cmap="bwr") { "l1": <RGBA array for the blue 'bwr' color>, "l2": <RGBA array for the white 'bwr' color>, "l3": <RGBA array for the red 'bwr' color>, }
- quick_min_max(data, max_size=1000000.0)[source]#
Adapted from pyqtgraph.ImageView. Estimate the min/max values of data by subsampling.
- subsample_array(arr, max_size=1000000.0, ignore_dims=None)[source]#
Subsamples an input array while preserving its relative dimensional proportions.
The dimensions (shape) of the array can be represented as:
\[[d_1, d_2, \dots d_n]\]The product of the dimensions can be represented as:
\[\prod_{i=1}^{n} d_i\]To find the factor
f
by which to divide the size of each dimension in order to get max_sizes
we must solve forf
in the following expression:\[\prod_{i=1}^{n} \frac{d_i}{\mathbf{f}} = \mathbf{s}\]The solution for
f
is is simply the nth root of the product of the dims divided by the max_size where n is the number of dimensions\[\mathbf{f} = \sqrt[n]{\frac{\prod_{i=1}^{n} d_i}{\mathbf{s}}}\]- Parameters:
arr (np.ndarray) – input array of any dimensionality to be subsampled.
max_size (int, default 1e6) – maximum number of elements in subsampled array
ignore_dims (Sequence[int], optional) – List of dimension indices to exclude from subsampling (i.e. retain full resolution). For example, ignore_dims=[0] will avoid subsampling along the first axis.
- Returns:
subsample of the input array
- Return type:
np.ndarray
- get_nearest_graphics(pos, graphics)[source]#
Returns the nearest
graphics
to the passed positionpos
in world space. Uses the distance betweenpos
and the center of the bounding sphere for each graphic.- Parameters:
- Returns:
nearest graphics to
pos
in order- Return type:
ndarray[Graphic]
- get_nearest_graphics_indices(pos, graphics)[source]#
Returns indices of the nearest
graphics
to the passed positionpos
in world space in order of closest to furtherst. Uses the distance betweenpos
and the center of the bounding sphere for each graphic.- Parameters:
- Returns:
indices of the nearest nearest graphics to
pos
in order- Return type:
ndarray[int]