0

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

Ruth
  • 1
  • 2
  • Can you provide the code you have tried and an explanation of what you want it to do differently? See http://stackoverflow.com/help/mcve – Abraham D Flaxman Feb 14 '16 at 19:55
  • Yup, I have modified the question to include an example. Thanks – Ruth Feb 15 '16 at 22:57
  • Cool, I think I understand what you are after. [The javascript for the linked brush plugin is here](https://github.com/jakevdp/mpld3/blob/master/src/plugins/linkedbrush.js), which shows the details that are hidden in the python source you linked to above. – Abraham D Flaxman Feb 17 '16 at 19:44

0 Answers0