Plotting with plotly
#
Plotly interface to CEBRA.
- cebra.integrations.plotly.plot_embedding_interactive(embedding, embedding_labels='grey', axis=None, markersize=1, idx_order=None, alpha=0.4, cmap='cool', title='Embedding', figsize=(5, 5), dpi=100, **kwargs)#
Plot embedding in a 3D dimensional space.
This is supposing that the dimensions provided to
idx_order
are in the range of the number of dimensions of the embedding (i.e., between 0 andcebra.CEBRA.output_dimension
-1).The function makes use of
plotly.graph_objects.Scatter
and parameters from that function can be provided as part ofkwargs
.- Parameters:
embedding (
Union
[ndarray
[tuple
[int
,...
],dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]],Tensor
]) – A matrix containing the feature representation computed with CEBRA.embedding_labels (
Union
[ndarray
[tuple
[int
,...
],dtype
[TypeVar
(_ScalarType_co
, bound=generic
, covariant=True)]],Tensor
,str
,None
]) –The labels used to map the data to color. It can be:
A vector that is the same sample size as the embedding, associating a value to each of the sample, either discrete or continuous.
A string, either time, then the labels will color the embedding based on temporality, or a string that can be interpreted as a RGB(A) color, then the embedding will be uniformly displayed with that unique color.
axis (
Optional
[Figure
]) – Optional axis to create the plot on.idx_order (
Optional
[Tuple
[int
]]) – A tuple (x, y, z) or (x, y) that maps a dimension in the data to a dimension in the 3D/2D embedding. The simplest form is (0, 1, 2) or (0, 1) but one might want to plot either those dimensions differently (e.g., (1, 0, 2)) or other dimensions from the feature representation (e.g., (2, 4, 5)).markersize (
float
) – The marker size.alpha (
float
) – The marker blending, between 0 (transparent) and 1 (opaque).cmap (
str
) – The Colormap instance or registered colormap name used to map scalar data to colors. It will be ignored if embedding_labels is set to a valid RGB(A).title (
str
) – The title on top of the embedding.dpi (
int
) – Figure resolution.kwargs –
Optional arguments to customize the plots. This dictionary includes the following optional arguments:
showlegend
: Whether to show the legend or not.discrete
: Whether the labels are discrete or not.col
: The column of the subplot to plot the embedding on.row
: The row of the subplot to plot the embedding on.template
: The template to use for the plot.
Note:
showlegend
can beTrue
only ifdiscrete
isTrue
. Seeplotly.graph_objects.Scatter
documentation for more details on which arguments to use.
Example
>>> import cebra >>> import numpy as np >>> X = np.random.uniform(0, 1, (100, 50)) >>> y = np.random.uniform(0, 10, (100, 5)) >>> cebra_model = cebra.CEBRA(max_iterations=10) >>> cebra_model.fit(X, y) CEBRA(max_iterations=10) >>> embedding = cebra_model.transform(X) >>> cebra_time = np.arange(X.shape[0]) >>> fig = cebra.plot_embedding_interactive(embedding, embedding_labels=cebra_time)
- Return type: