Announcing Dash Bio 1.0.0 🎉 : a one-stop-shop for bioinformatics and drug development visualizations.

Parallel Categories Diagram, linked brushing in Python

I do not get an error when I am trying to plot the following code and still, both charts do not get linked.
I am using Jupyter Notebook.
These are the versions:
You are using Jupyter notebook.

The version of the notebook server is: 6.0.1
The server is running on this version of Python:
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)]

Current Kernel Information:

Python 3.7.7 (default, May 6 2020, 04:59:01)
Type ‘copyright’, ‘credits’ or ‘license’ for more information
IPython 7.16.1 – An enhanced Interactive Python. Type ‘?’ for help.

CODE:

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

pyo.init_notebook_mode()

Build dimensions

categorical_dimensions = [‘insured_education_level’, ‘police_report_available’, ‘fraud_reported’];

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

Build colorscale

color = np.zeros(len(claims), dtype=‘uint8’)
colorscale = [[0, ‘gray’], [1, ‘firebrick’]]

Build figure as FigureWidget

fig = go.FigureWidget(
data=[go.Scatter(x=claims.policy_annual_premium, y=claims.total_claim_amount,
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’: ‘Annual premium’},
yaxis={‘title’: ‘Total Claim Amount’, ‘domain’: [0.6, 1]},
dragmode=‘lasso’, hovermode=‘closest’)

Update color callback

def update_color(trace, points, state):
# Update scatter selection
fig.data[0].selectedpoints = points.point_inds

# Update parcats colors
new_color = np.zeros(len(claims), dtype='uint8')
new_color[points.point_inds] = 1
fig.data[1].line.color = new_color

Register callback on scatter selection…

fig.data[0].on_selection(update_color)

and parcats click

fig.data[1].on_click(update_color)

fig.show()