[Python] Highlight certain points in Plotly through dropbown bar

Discussão em 'Python' iniciado por Stack, Setembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to make an interactive PCA plot with Plotly. I am having some troubles in highlighting a certain marker that a user wants to see in the plot.

    Instead of highlighting a marker there is a square around it.

    My attempt at the code:

    from sklearn.datasets import make_blobs
    import pandas as pd
    import plotly.express as px
    X, y = make_blobs(n_samples=30, centers=3, n_features=2,
    random_state=0)
    ff = PCA(n_components= 2)
    clusters = pd.DataFrame(data = ff.fit_transform(X), columns = ['PC1', 'PC2'])
    clusters['target'] = y
    id = [0, 4, 7]
    updatemenus = [dict(buttons=list(dict(label = idd ,method = 'relayout', args = ['shapes', [dict(markers = dict(color = 'Red', size = 120), type = "markers", xref = 'x', yref = 'y', x0 = clusters.loc[idd, 'PC1'], y0=clusters.loc[idd, 'PC2'])]]) for idd in id))]
    fig = px.scatter(clusters, x = 'PC1', y = 'PC2', color = 'target', hover_data = ['target'])
    fig.update_layout(updatemenus = updatemenus)
    fig.show()


    [​IMG]

    What am I doing wrong :)

    Continue reading...

Compartilhe esta Página