1

I have a set of data in my research project, and each data point contains lots of related information and it is impossible to show all of them in a figure. What I would like to do to visualize these data is to plot the data points using their two key parameters, and when the mouse cursor hovers over one data point, it shows all information related to this data point. I am wondering if there are any ways to implement this?

Thanks!

username123
  • 913
  • 1
  • 11
  • 29

1 Answers1

3

You have a matplotlib example that provides something like what you are asking here. @root gave an answer here that provides a basic interface with output for the console (by mouse click over the points):

from matplotlib.pyplot import figure, show
import numpy as npy
from numpy.random import rand

if 1: # picking on a scatter plot (matplotlib.collections.RegularPolyCollection)

    x, y, c, s = rand(4, 100)
    def onpick3(event):
        ind = event.ind
        print 'onpick3 scatter:', ind, npy.take(x, ind), npy.take(y, ind)

    fig = figure()
    ax1 = fig.add_subplot(111)
    col = ax1.scatter(x, y, 100*s, c, picker=True)
    #fig.savefig('pscoll.eps')
    fig.canvas.mpl_connect('pick_event', onpick3)

show()

Yet I would suggest mpldatacursor. @moooeeeep gave an example of it's use here:

import matplotlib.pyplot as plt
from mpldatacursor import datacursor
import random

fig, ax = plt.subplots()
ax.set_title('Click on a dot to display its label')

# Plot a number of random dots
for i in range(1, 1000):
    ax.scatter([random.random()], [random.random()], label='$ID: {}$'.format(i))

# Use a DataCursor to interactively display the label for a selected line...
datacursor(formatter='{label}'.format)

plt.show()

With this result:

mpldatacursor example

Community
  • 1
  • 1
armatita
  • 12,825
  • 8
  • 48
  • 49