Point and line tooltips in matplotlib?

前端 未结 3 1228
悲哀的现实
悲哀的现实 2020-12-06 11:19

I have a graph with some line segments (LineCollection) and some points. These lines and points have some values associated with them that are not graphed. I would like to b

3条回答
  •  难免孤独
    2020-12-06 11:44

    It's an old thread, but in case anyone is looking for how to add tooltips to lines, this works:

    import matplotlib.pyplot as plt
    import numpy as np
    import mpld3
    
    f, ax = plt.subplots()
    x1 = np.array([0,100], int)
    x2 = np.array([10,110], int)
    y = np.array([0,100], int)
    
    line = ax.plot(x1, y)
    mpld3.plugins.connect(f, mpld3.plugins.LineLabelTooltip(line[0], label='label 1'))
    
    line = ax.plot(x2, y)
    mpld3.plugins.connect(f, mpld3.plugins.LineLabelTooltip(line[0], label='label 2'))
    
    mpld3.show()
    

提交回复
热议问题