spateo.plotting.static.utils
#
Module Contents#
Classes#
Functions#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Compute bounds on a space with appropriate padding |
|
|
|
|
|
|
|
|
|
|
|
Create an interactive bokeh plot of a UMAP embedding. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
https://matplotlib.org/3.1.0/gallery/axes_grid1/demo_colorbar_with_inset_locator.html |
|
https://stackoverflow.com/questions/33737736/matplotlib-axis-arrow-tip |
|
Function to automatically calculate the value for the scale parameter of quiver plot, adapted from scVelo |
|
|
|
|
|
|
|
s has to be a StreamplotSet |
|
Save a figure from pyplot. |
|
|
|
|
|
|
|
|
|
|
|
Subset and reorder data array, given array and corresponding array index. |
|
When plotting continuous variables, configure a normalizer object for the purposes of mapping the data to varying |
|
Given a dictionary of plot parameters (kwargs_dict) and any number of additional keyword arguments, |
|
|
|
Computes a hierarchical clustering for the categories given by 'cat_key'. |
|
Plots dendrogram on the provided Axes, using the dendrogram information stored in .uns[dendrogram_key] |
- spateo.plotting.static.utils._get_extent(points)[source]#
Compute bounds on a space with appropriate padding
- spateo.plotting.static.utils._matplotlib_points(points, ax=None, labels=None, values=None, highlights=None, cmap='Blues', color_key=None, color_key_cmap='Spectral', background='white', width=7, height=5, show_legend=True, vmin=2, vmax=98, sort='raw', frontier=False, contour=False, ccmap=None, calpha=0.4, sym_c=False, inset_dict={}, show_colorbar=True, projection=None, geo=False, **kwargs)[source]#
- spateo.plotting.static.utils._datashade_points(points, ax=None, labels=None, values=None, highlights=None, cmap='blue', color_key=None, color_key_cmap='Spectral', background='black', width=7, height=5, show_legend=True, vmin=2, vmax=98, sort='raw', projection='2d', **kwargs)[source]#
- spateo.plotting.static.utils.interactive(umap_object, labels=None, values=None, hover_data=None, theme=None, cmap='Blues', color_key=None, color_key_cmap='Spectral', background='white', width=7, height=5, point_size=None)[source]#
Create an interactive bokeh plot of a UMAP embedding. While static plots are useful, sometimes a plot that supports interactive zooming, and hover tooltips for individual points is much more desireable. This function provides a simple interface for creating such plots. The result is a bokeh plot that will be displayed in a notebook. Note that more complex tooltips etc. will require custom code – this is merely meant to provide fast and easy access to interactive plotting. :param umap_object: A trained UMAP object that has a 2D embedding. :type umap_object: trained UMAP object :param labels: An array of labels (assumed integer or categorical),
one for each data sample. This will be used for coloring the points in the plot according to their label. Note that this option is mutually exclusive to the
values
option.- Parameters
- values : array, shape (n_samples,) (optional, default None)
An array of values (assumed float or continuous), one for each sample. This will be used for coloring the points in the plot according to a colorscale associated to the total range of values. Note that this option is mutually exclusive to the
labels
option.- hover_data : DataFrame, shape (n_samples, n_tooltip_features)
- (optional
A dataframe of tooltip data. Each column of the dataframe should be a Series of length
n_samples
providing a value for each data point. Column names will be used for identifying information within the tooltip.- None) : default
A dataframe of tooltip data. Each column of the dataframe should be a Series of length
n_samples
providing a value for each data point. Column names will be used for identifying information within the tooltip.- theme : string (optional, default None)
A color theme to use for plotting. A small set of predefined themes are provided which have relatively good aesthetics. Available themes are:
’blue’
’red’
’green’
’inferno’
’fire’
’viridis’
’darkblue’
’darkred’
’darkgreen’
- cmap : string (optional, default 'Blues')
The name of a matplotlib colormap to use for coloring or shading points. If no labels or values are passed this will be used for shading points according to density (largely only of relevance for very large datasets). If values are passed this will be used for shading according the value. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.
- color_key : dict or array, shape (n_categories) (optional, default None)
A way to assign colors to categoricals. This can either be an explicit dict mapping labels to colors (as strings of form ‘#RRGGBB’), or an array like object providing one color for each distinct category being provided in
labels
. Either way this mapping will be used to color points according to the label. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.- color_key_cmap : string (optional, default 'Spectral')
The name of a matplotlib colormap to use for categorical coloring. If an explicit
color_key
is not given a color mapping for categories can be generated from the label list and selecting a matching list of colors from the given colormap. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.- background : string (optional, default 'white)
The color of the background. Usually this will be either ‘white’ or ‘black’, but any color name will work. Ideally one wants to match this appropriately to the colors being used for points etc. This is one of the things that themes handle for you. Note that if theme is passed then this value will be overridden by the corresponding option of the theme.
- width : int (optional, default 800)
The desired width of the plot in pixels.
- height : int (optional, default 800)
The desired height of the plot in pixels
- Returns
- spateo.plotting.static.utils.scatter_with_colorbar(fig, ax, x, y, c, cmap, **scatter_kwargs)[source]#
- spateo.plotting.static.utils.scatter_with_legend(fig, ax, df, font_color, x, y, c, cmap, legend, **scatter_kwargs)[source]#
- spateo.plotting.static.utils.set_colorbar(ax, inset_dict={})[source]#
https://matplotlib.org/3.1.0/gallery/axes_grid1/demo_colorbar_with_inset_locator.html
- spateo.plotting.static.utils.arrowed_spines(ax, columns, background='white')[source]#
https://stackoverflow.com/questions/33737736/matplotlib-axis-arrow-tip modified based on Answer 6
- spateo.plotting.static.utils.quiver_autoscaler(X_emb, V_emb)[source]#
Function to automatically calculate the value for the scale parameter of quiver plot, adapted from scVelo :param X_emb: X, Y-axis coordinates :type X_emb: np.ndarray :param V_emb: Velocity (U, V) values on the X, Y-axis :type V_emb: np.ndarray
- Returns
The scale for quiver plot
- spateo.plotting.static.utils._plot_traj(y0, t, args, integration_direction, ax, color, lw, f)[source]#
- spateo.plotting.static.utils.set_stream_line_alpha(s=None, alpha=1)[source]#
s has to be a StreamplotSet
- spateo.plotting.static.utils.save_fig(path=None, prefix=None, dpi=None, ext='pdf', transparent=True, close=True, verbose=True)[source]#
Save a figure from pyplot. code adapated from http://www.jesshamrick.com/2012/09/03/saving-figures-from-pyplot/ :param path: The path (and filename, without the extension) to save_fig the
figure to.
- spateo.plotting.static.utils.plot_polygon(polygon, margin=1, fc='#999999', ec='#000000', fill=True, ax=None, **kwargs)[source]#
- spateo.plotting.static.utils.save_return_show_fig_utils(save_show_or_return: typing_extensions.Literal[save, show, return, both, all], show_legend: bool, background: str, prefix: str, save_kwargs: Dict, total_panels: int, fig: matplotlib.figure.Figure, axes: matplotlib.axes.Axes, return_all: bool, return_all_list: Union[List, Tuple, None]) Optional[Tuple] [source]#
- spateo.plotting.static.utils._get_array_values(X: Union[numpy.ndarray, scipy.sparse.base.spmatrix], dim_names: pandas.Index, keys: List[str], axis: typing_extensions.Literal[0, 1], backed: bool)[source]#
Subset and reorder data array, given array and corresponding array index.
- Parameters
- X
np.ndarray or scipy sparse matrix
- dim_names
pd.Index Names of
- keys
list of str Index names to subset
- axis
int, 0 or 1 Subset rows or columns of ‘X’ (0 for rows, 1 for columns)
- backed
bool Interfaces w/ AnnData objects; is True if AnnData is backed to disk
- Returns
np.ndarray
- Return type
matrix
- spateo.plotting.static.utils.check_colornorm(vmin: Union[None, float] = None, vmax: Union[None, float] = None, vcenter: Union[None, float] = None, norm: Union[None, matplotlib.colors.Normalize] = None)[source]#
When plotting continuous variables, configure a normalizer object for the purposes of mapping the data to varying color intensities.
- Parameters
- vmin
optional float The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.
- vmax
optional float The data value that defines 1.0 in the normalization. Defaults to the the max value of the dataset.
- vcenter
optional float The data value that defines 0.5 in the normalization
- norm
optional matplotlib.colors.Normalize object Optional already-initialized normalizing object that scales data, typically into the interval [0, 1], for the purposes of mapping to color intensities for plotting. Do not pass both ‘norm’ and ‘vmin’/’vmax’, etc.
- Returns
- matplotlib.colors.Normalize object
The normalizing object that scales data, typically into the interval [0, 1], for the purposes of mapping to color intensities for plotting.
- Return type
normalize
- spateo.plotting.static.utils.deduplicate_kwargs(kwargs_dict, **kwargs)[source]#
Given a dictionary of plot parameters (kwargs_dict) and any number of additional keyword arguments, merge the parameters into a single consolidated dictionary to avoid argument duplication errors. If kwargs_dict contains a key that matches any of the additional keyword arguments, only the value in kwargs_dict is kept.
- Parameters
- kwargs_dict
dict Each key is a variable name and each value is the value of that variable
- kwargs
Any additional keyword arguments, the keywords of which may or may not already be in ‘kwargs_dict’
- spateo.plotting.static.utils._dendrogram_sig(data: numpy.ndarray, method: str, **kwargs) Tuple[List[int], List[int], List[int], List[int]] [source]#
- spateo.plotting.static.utils.dendrogram(adata: anndata.AnnData, cat_key: str, n_pcs: int = 30, use_rep: Union[None, str] = None, var_names: Union[None, List[str]] = None, cor_method: str = 'pearson', linkage_method: str = 'complete', optimal_ordering: bool = False, key_added: Union[None, str] = None, inplace: bool = True) Optional[Dict[str, Any]] [source]#
Computes a hierarchical clustering for the categories given by ‘cat_key’.
By default, the PCA representation is used unless .X has less than 50 variables.
Alternatively, a list of var_names (e.g. genes) can be given. If this is the case, will subset to these features and use them for the dendrogram.
- Parameters
- adata
object of class anndata.AnnData
- cat_key
Name of key in .obs specifying group labels for each sample
- n_pcs
Number of principal components to use in computing hierarchical clustering
- use_rep
Entry in .obsm to use for computing hierarchical clustering
- var_names
List of genes to define a subset of ‘adata’ to compute hierarchical clustering directly on expression values.
- cor_method
Correlation method to use. Options are ‘pearson’, ‘kendall’, and ‘spearman’
- linkage_method
Linkage method to use. See
scipy.cluster.hierarchy.linkage()
for more information.- optimal_ordering
Same as the optimal_ordering argument of
scipy.cluster.hierarchy.linkage()
which reorders the linkage matrix so that the distance between successive leaves is minimal.- key_added
Sets key in .uns in which dendrogram information is saved. By default, the dendrogram information is added to .uns[f’dendrogram_{cat_key}’].
- inplace
If True, adds dendrogram information to adata.uns[key_added], else this function returns the information.
- Returns
If inplace=False, returns dendrogram information, else adata object is updated in place with information stored in adata.uns[key_added].
- spateo.plotting.static.utils.plot_dendrogram(dendro_ax: matplotlib.axes.Axes, adata: anndata.AnnData, cat_key: str, dendrogram_key: Union[None, str] = None, orientation: typing_extensions.Literal[top, bottom, left, right] = 'right', remove_labels: bool = True, ticks: Union[None, Collection[float]] = None)[source]#
Plots dendrogram on the provided Axes, using the dendrogram information stored in .uns[dendrogram_key]
- Parameters
- dendro_ax
object of class matplotlib.axes.Axes
- adata
object of class anndata.AnnData Contains dendrogram information as well as the data that will be plotted (and was used to hierarchically cluster)
- cat_key
Key in .obs containing category labels for all samples
- dendrogram_key
- orientation
Specifies dendrogram placement relative to the plotting window. Options: ‘top’, ‘bottom’, ‘left’, ‘right’
- remove_labels
Removes labels along the side that dendrogram is on, if any
- ticks
Assumes original ticks come from scipy.cluster.hierarchy.dendrogram, but if not can also pass a list of custom tick values.