0
votes

Is there any way to have one gnuplot window, and then from within that window, cycle forward to different plots?

To be a little more clear, say that I wanted to plot sin(x), cos(x), and tan(x) in this way. First, a window would appear with sin(x) on it, then when I hit some key, the same window would then show me cos(x), and then finally, upon the next keystroke, it would show me tan(x).

I've only been able to find information on displaying multiple plots at the same time, on the same window. In my case, my data is per day, and I've got about 300 days to look at.

It would be sort of the same as opening 300 images in an image viewer. You just hit "next" to view the next one. I'm not able to export to images, though, since I need to be able to zoom and inspect each individual plot.

I'm using wxt, and calling gnuplot from a C program with popen(), if that matters.

Anyone have any ideas?

1

1 Answers

1
votes

You can use pause mouse keypress to catch keyboard input after a plot. The key code will be available within gnuplot in the MOUSE_KEY variable (see help pause). For example, the following plots a sine curve and waits for keyboard input; pressing "a" will shift the curve to the left and "d" will shift the curve to the right:

set xrange [-10:10]
x0 = 0.

while 1 {
    plot sin(x-x0)
    pause mouse keypress
    print "Key pressed: ", MOUSE_KEY
    if (MOUSE_KEY == 100) {      # "d" pressed
        x0 = x0 + 0.1 }
    else {
        if (MOUSE_KEY == 97) {   # "a" pressed
            x0 = x0 - 0.1
        }
        else {
            break
        }
    }
}

This works for the X terminal, but at least for it doesn't seem to work for wxt. I'm not sure if it's possible to send key presses back to gnuplot from wxt.

Update

A possible simpler solution that also works with the wxt terminal is to use the bind command:

set xrange [-10:10]
x0 = 0.
bind a "x0 = x0+0.1; replot"
bind d "x0 = x0-0.1; replot"
plot sin(x-x0)