plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Plotly interactive Multiplot is not working in Google Colab/Jupyter Notebook

Open kaansen97 opened this issue 4 years ago • 1 comments

Hello I'm using Google colab to display multiplot that's why I tried to create one scatterplot with 3 scatters in it and under that, there is a parallel categories plot that should be connected to scatter but when I try to select a group of points in scatter, I cannot change color in parcat it's always grey, I think those functions such as on_click and on_selection does not work but I couldn't replace them with another code can someone help me? Also tried dash but still not interactive and tried those graph in original site those not working too

https://plotly.com/python/click-events/

` import plotly.graph_objects as go from ipywidgets import widgets import pandas as pd import numpy as np

Build parcats dimensions

categorical_dimensions = ['Layer Input', 'Layer 2', 'Layer 3','Layer Output'];

dimensions = [dict(values=dfTot[label], label=label) for label in categorical_dimensions]

Build colorscale

color = np.zeros(len(dfTot), dtype='uint8') colorscale = [[0, 'gray'], [1, 'firebrick']]

Build figure as FigureWidget

fig = go.FigureWidget( data=[ go.Scatter(x=layer_activation1[:,0], y=layer_activation1[:,1],showlegend = False,hovertemplate =y+"
"+"Cluster Groupe : "+df2['Layer 2']+"
"+"Layer 2"'', marker={'color': 'gray'}, mode='markers', selected={'marker': {'color': 'firebrick'}}, unselected={'marker': {'opacity': 0.3}}),

      go.Scatter(x=layer_activation2[:,0], y=layer_activation2[:,1],showlegend = False,hovertemplate =y+"<br>"+"Cluster Groupe : "+df3['Layer 3']+"<br>"+"Layer 3"'<extra></extra>',
marker={'color': 'gray'}, mode='markers', selected={'marker': {'color': 'firebrick'}},
unselected={'marker': {'opacity': 0.3}}), 

      
      go.Scatter(x=layer_activation3[:,0], y=layer_activation3[:,1],showlegend = False,hovertemplate =y+"</br>"+"Cluster Groupe : "+df4['Layer Output']+"<br>"+"Layer Output"'<extra></extra>',
marker={'color': 'gray'}, mode='markers', selected={'marker': {'color': 'firebrick'}},
unselected={'marker': {'opacity': 0.3}}), 

go.Parcats(
    domain={'y': [0, 0.4]}, dimensions=dimensions,
    line={'colorscale': colorscale, 'cmin': 0,
          'cmax': 1, 'color': color, 'shape': 'hspline'})
])

fig.update_layout( height=800, xaxis={'title': 'Axis x'}, yaxis={'title': 'Axis y', 'domain': [0.6, 1]}, dragmode='lasso', hovermode='closest')

Update color callback

def update_color(trace, points, state): new_color = np.zeros(len(dfTot), dtype='uint8') # Update scatter selection fig.data[0].selectedpoints = points.point_inds new_color[points.point_inds] = 1 fig.data[3].line.color = new_color

fig.data[1].selectedpoints = points.point_inds
new_color[points.point_inds] = 1
fig.data[3].line.color = new_color

fig.data[2].selectedpoints = points.point_inds
# Update parcats colors

new_color[points.point_inds] = 1
fig.data[3].line.color = new_color

Register callback on scatter selection...

fig.data[0].on_selection(update_color) fig.data[1].on_selection(update_color) fig.data[2].on_selection(update_color)

and parcats click

fig.data[3].on_click(update_color)

f ` This is the graph I am trying to connect

kaansen97 avatar Apr 02 '22 09:04 kaansen97

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

gvwilson avatar Jul 04 '24 13:07 gvwilson