Monday, June 4, 2012

Plot an interactive svg graph using gnuplot

In this post an example of plotting an interactive svg graph using gnuplot is talked.

First, run the following gnuplot plotting script.

set term svg mouse jsdir "./js"  
set output "sincos.svg"
plot sin(x) w l lc rgb"#ff0000", cos(x) w l lc rgb"#00ff00"
set output

And a file called "sincos.svg" is plotted. As we specified in the script that the javascript file is in directory "./js", "gnuplot-dir/share/js" have to be copied to the current directory (windows operating system, and if you use linux maybe the directory should be /usr/local/share/gnuplot/gnuplot-version/js). This time open the file, and you can find when you click the graph, the coordinate of the current point will be displayed. And when you click the legend, the cooresponding line will be invisible, and click it again, the line will visible.

The jsdir can also be a url location. And this is is usually appropriate if you are embedding the svg into a web page. For example, command --- set term svg mouse jsdir "http://gnuplot.sourceforge.net/demo_svg_4.6/" can be used.

set term svg mouse jsdir "http://gnuplot.sourceforge.net/demo_svg_4.6/"
set output "sincos.svg"
plot sin(x) w l lc rgb"#ff0000", cos(x) w l lc rgb"#00ff00"
set output

9 comments:

  1. It seems the script can be open with firefox but the mouse isn't 'enahnced' in browser's box...I can't neither use gpl to plot the .svg .... What do you use to open .svg and actually play interactively with the mouse ?
    Thanks

    ReplyDelete
    Replies
    1. I use the newest version of firefox. And following the instructions the interactive svg file is just interactive. If you can provide the error information, maybe I can give you more help.

      Delete
    2. Maybe it came that in my gp 4.6 packages the share/js is full of canvas script and nothing about .svg, the gnuplot_mouse.js is canvas terminal script (as far as I understand the commented line);
      but it doesn't work neither if ichange your first line by

      set term canvas standalone mousing jsdir "./js"

      In this case nothing is read on firefox

      Did I miss somethning in the gp installation or is .svg an optionnal packages (I'm on winXP)

      Thanks

      Delete
  2. Oh sorry I've found the gnuplot_svg.js file which contains the routine.
    My problem is that I have no errors from the load 'mouse.svg' (your script) or by reading the .svg file in firefox; it works but without the interactivity.

    ReplyDelete
    Replies
    1. Try the following script:

      set term svg mouse jsdir "http://gnuplot.sourceforge.net/demo_svg_4.6/"
      set output "sincos.svg"
      plot sin(x) w l lc rgb"#ff0000", cos(x) w l lc rgb"#00ff00"
      set output

      Make sure there is internet connection. And open the outputted file with firefox. If it is still not interactive, then maybe the problem comes from your firefox.

      Delete
  3. Ok it works ! The mouse tracking and legend's click put visible/invisible the curve.
    So does it mean my gnuplot_svg.js or the others *.js are not complete ?

    ReplyDelete
  4. Thanks again for the help ! Another thing; I've tried to put .svg on an html page, finally the visible/invisible legend by mouse clicking is ok but the mouse coordinates does not appear on left or right clicking mouse ('a contrario' the .svg file locally does work fully...). Do you have any idea ? Maybe the jsdir on sourceforge is not complete ?

    ReplyDelete
    Replies
    1. If the graph on page "http://gnuplot.sourceforge.net/demo_svg_4.6/" is all right, the problem may be comes from your browser.

      Delete

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.