Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Hover over scatter plot

by Anonymous Monk
on Jun 18, 2014 at 02:08 UTC ( #1090236=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:


Is there any way to just hover over a specific plot point on scatter plot and find out the x and y value of that point?

I can see it is easy to do this in Python. But I am interested in Perl solution as I have a large scale Perl program that does some other data generation.

Thanks. Andy

Replies are listed 'Best First'.
Re: Hover over scatter plot
by zentara (Archbishop) on Jun 18, 2014 at 09:23 UTC
    You might want to look at Tk::Chart. For a simple example, you can use the canvas like in the following example. It's up to you to correlate the point plots with their values.
    #!/usr/bin/perl use Tk; my $mw = MainWindow->new(); $mw->geometry("600x400+50+50"); $canvas = $mw->Canvas(width => 600, height => 400)->pack(); $canvas->Tk::bind("<Button-1>", [ \&print_xy, Ev('x'), Ev('y') ]); sub print_xy { print "@_\n"; my ($canv, $x, $y) = @_; print '(x,y) = ', $canv->canvasx($x), ', ', $canv->canvasy($y),"\n" +; } MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Hover over scatter plot
by LanX (Chancellor) on Jun 18, 2014 at 03:25 UTC
    > I can see it is easy to do this in Python.

    Really? Great! :)

    If you show us the Python code then, we will better understand which application you are talking about.

    Cheers Rolf

    (addicted to the Perl Programming Language)

Re: Hover over scatter plot
by Anonymous Monk on Jun 18, 2014 at 02:41 UTC
    What scatter plot where?
Re: Hover over scatter plot
by ambrus (Abbot) on Jun 18, 2014 at 18:58 UTC

    I usually draw plots using gnuplot. See Plot a spiral with gnuplot for an educational example.

    Most interactive terminals (rendering frontend drivers) of gnuplot support using the mouse. These include the wxt and x11 terminals.

    If you make a plot on such a terminal, then hover the mouse over the plot window, the coordinates of the hovered points will show up printed in the corner of the plot window. If you click the mouse, gnuplot stores the coordinates in the variables MOUSE_X and MOUSE_Y, which you can query with the print statement of gnuplot. I believe you can even bind a callback function gnuplot will execute on mouse clicks, see the gnuplot manual for details.

    There is one limitation of mouse handling that is worth noting. If you are using a multiplot (multiple independent plot areas side by side in a window), then you can get the coordinates corresponding to the last plot area only.

      Chart::Gnuplot works with Gnuplot in Perl. Just setting the "terminal" option of the "chart" object (e.g. "x11" in Linux or "windows" in Windows) will pop up an interactive window with mouse hover feature, i.e.

      my $chart = Chart::Gnuplot->new( terminal => "x11", .... );
      Here has more examples about Chart::Gnuplot.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1090236]
[trahulprajapati]: Hello All, Good Morning

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-06-28 12:53 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (637 votes). Check out past polls.