AdaptiveMotorControlLab / CEBRA

Learnable latent embeddings for joint behavioral and neural analysis - Official implementation of CEBRA
https://cebra.ai
Other
875 stars 66 forks source link

Legend labels are not visible while using interactive plots #121

Closed nastya236 closed 7 months ago

nastya236 commented 7 months ago

Is there an existing issue for this?

Bug description

Bug description

I have discrete auxiliary variables that I am using to color my embeddings. The color works fine, but I do not know which color corresponds to which label. I tried adding a legend like I would in plotly.graph_objects.Scatter, this did not produce an error, but it also does not produce a legend. How can I get a label to be associated with the embedding_label colors? Below is my code for generating the plot. 'crop_bx' is a 1xN vector.

cebra_model = cebra.CEBRA(
    model_architecture = "offset10-model-mse",
    batch_size = 512,
    temperature_mode="auto",
    learning_rate = 0.0001,
    max_iterations = 1000,
    time_offsets = 10,
    output_dimension = 3,
    conditional='time_delta',
    device='cuda_if_available',
    distance='euclidean',
    verbose=True,
)

cebra_model.fit(crop_neural, crop_bx)
embedding = cebra_model.transform(crop_neural)

fig = cebra.integrations.plotly.plot_embedding_interactive(embedding, embedding_labels= crop_bx, title = "CEBRA-Behavior", cmap='tab20', legend=np.unique(crop_bx).astype(str), showlegend = True)

fig.show()

Operating System

Windows 10

CEBRA version

cebra version: '0.3.1'

Device type

cpu

Steps To Reproduce

No response

Relevant log output

No response

Anything else?

No response

Code of Conduct

MMathisLab commented 7 months ago

thanks @SpencerBowles cc @nastya236 !

It seems legend is hardcoded to False/not passed to kwargs: https://github.com/AdaptiveMotorControlLab/CEBRA/blob/6a6a07d1b61c1d956d1638bc2e5d7b1bd1c5f1c9/cebra/integrations/plotly.py#L123 and we could modify to pass to L#130 https://github.com/AdaptiveMotorControlLab/CEBRA/blob/6a6a07d1b61c1d956d1638bc2e5d7b1bd1c5f1c9/cebra/integrations/plotly.py#L130

stes commented 7 months ago

The way the kwargs are handled seems off. I'll make a proposal