@ianhi (hope the ping is not an issue)
I am trying to create a scatter plot that changes the visible points based on a slider (based on the example in the documentation). This is within a wider plot where as the slider changes, I also want only the name of the visible data points to appear and another scatter plot to be affected by the slider value changes.
Thing is, I managed to make this work once. But after that, probably due to changes in the environment or versions, it stopped working in the following ways:
- I can make the scatter plot that generates the controller change with the slider. But, even though the changes occur, the terminal raises an error every time the slider changes: âTypeError: â<=â not supported between instances of âintâ and âNoneTypeââ â this seems related to the alpha setting of the matplotlib artist by looking at the error chain.
- Now changes in the controller are not sent to the other functions that generate the text or the other scatter plot. So only the original scatter plot changes, but the names donât change from the ones that first appear, and the other scatter plot is unaffected.
Here is the relevant code
def threshold_sn(x, y, score):
sn_colors = np.array([list(color) for color in colours_sn])
sn_colors[:, -1] = 1
deltas = np.abs(scores_sn - score)
idx = deltas < 0.01
deltas /= deltas.max()
sn_colors[~idx, -1] = np.clip(0.6 - deltas[~idx], 0, 1)
return sn_colors
def threshold_sl(x, y, score):
sl_colors = np.array([list(color) for color in colours_sl])
sl_colors[:, -1] = 1
deltas = np.abs(scores_sl - score)
idx = deltas < 0.01
deltas /= deltas.max()
sl_colors[~idx, -1] = np.clip(0.6 - deltas[~idx], 0, 1)
return sl_colors
controls = iplt.scatter(x=sn[:, 0],
y=sn[:, 1],
s=14,
linewidth=0.3,
edgecolors='gray',
score=(0, 1, 100),
c=threshold_sn)
# The below generates the second scatter plot, but it does not change with the slider.
iplt.scatter(x=sl[:, 0], y=sl[:, 1], s=14, c=threshold_sl, edgecolors='gray', linewidth=0.3, controls=controls)
scores_sl and scores_sn are lists contaning the scores of each individual data point. I donât think the issue is there because it has worked before (and still works on the controller scatter plot.
This is in JupyterLab (MacOS), and here is the version number of (maybe) relevant packages:
ipympl = 0.9.3
ipywidgets = 8.0.6
jupyterlab-widgets = 3.0.7
matplotlib = 3.7.1
mpl-interactions = 0.23.0
numpy = 1.25.0
pandas = 2.0.2
python = 3.9
jupyter lab = 4.0.2
Thanks in advance!