0

I tried the tooltip example in MPLD3. However, in my figure, I have several subplots with the linked x axis (length of data is the same, I am plotting different column of a dataframe). With the code below, I was able to see the tooltip when I move the mouse in the last subplot. However, I would like to do that when I move mouse in any subplot. How can I achieve that? I guess it should be sort of like the LinkedBrush example. I just not sure how to write my plugin to handle various number of subplots.

The following code creates a figure that on the bottom subplot has the tooltip.

import matplotlib.pyplot as plt
import numpy as np
import mpld3
from mpld3 import plugins, utils
N=30
fig, axes = plt.subplots(3, 1, figsize=(6,10), sharex='col')
for i in range(3):
    points1=axes[i].scatter(range(N),np.random.random(size=N), color='b',marker='.')
labels0 = [ 'point {0}'.format(i + 1) for i in range(N)]
tooltip = plugins.PointLabelTooltip(points1, labels0)
plugins.connect(fig, tooltip)
mpld3.save_html(fig, 'test.html')

1 Answers1

2

You accomplish this by putting the tooltip creation code into your loop:

import matplotlib.pyplot as plt
import numpy as np
import mpld3
from mpld3 import plugins, utils
N=30
fig, axes = plt.subplots(3, 1, figsize=(6,10), sharex='col')
for i in range(3):
    points1=axes[i].scatter(range(N),np.random.random(size=N), color='b',marker='.')
    labels0 = [ 'point {0}'.format(i + 1) for i in range(N)]
    tooltip = plugins.PointLabelTooltip(points1, labels0)
    plugins.connect(fig, tooltip)
mpld3.save_html(fig, 'test.html')
Abraham D Flaxman
  • 2,969
  • 21
  • 39