I am using mpld3 to draw a series of scatter plots.
I have used the PointLabelTooltip successfully. But I would also like to use the LinkedBrush feature to highlight points with the same characteristic.
For example, I have drawn a scatter plot of the sequencing depth of 70 genes in 20 bacteria. If I hover over a dot, it tells me which gene it refers to. But I would also like it to highlight the dot which represents the same gene in the other bacteria.
#Make an array of 20 bacteria each with 70 genes
a = np.random.randint(500, size=(20, 70))
bacteria = ["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15", "b16", "b17", "b18", "b19", "b20"]
genes = ["g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g9", "g10", "g11", "g12", "g13", "g14", "g15", "g16", "g17", "g18", "g19", "g20", "g21", "g22", "g23", "g24", "g25", "g26", "g27", "g28", "g29", "g30", "g31", "g32", "g33", "g34", "g35", "g36", "g37", "g38", "g39", "g40", "g41", "g42", "g43", "g44", "g45", "g46", "g47", "g48", "g49", "g50", "g51", "g52", "g53", "g54", "g55", "g56", "g57", "g58", "g59", "g60", "g61", "g62", "g63", "g64", "g65", "g66", "g67", "g68", "g69", "g70"]
fig, ax = plt.subplots(1, a.shape[0], sharey="row", figsize=(10, 3.5))
labels = []
for i in range(a.shape[0]):
xlist = np.random.normal(1, 0.1, len(a[i,:]))
points = ax[i].scatter(xlist, a[i,:])
ax[i].set_ylim(0,500)
ax[i].xaxis.set_major_locator(pylab.NullLocator())
ax[i].set_xlabel(bacteria[i])
labels.append(genes[i])
tooltip = plugins.PointLabelTooltip(points, labels=labels)
plugins.connect(fig, tooltip)
mpld3.display()
I want to modify the linkedBrush plugin to highlight the dots from the same gene in different bacteria:
plugins.connect(fig, plugins.LinkedBrush(points))
I have looked at the source code (https://mpld3.github.io/_modules/mpld3/plugins.html) but this does not seem to contain enough info in the LinkedBrush module to modify.
Any suggestions of how I might implement this would greatly appreciated.
Thanks