GNUPLOT cannot zoom in - linux

I am having an issue where I am unable to zoom in on my GNUPLOT. I created a bash script that records various resource information, and displays this information via the following command.
gnuplot -e persist "set title 'Resource monitor' ; set timefmt '%y/%m/%d-%H:%M:%S' ; set xdata time ; set xlabel 'TIME' ; set ylabel 'PERCENT' set yrange [0:101]" -e "plot '${cpuResFile}' using 1:2 title 'CPU' smooth Bezier, '${memResFile}' using 1:2 title 'MEM' smooth Bezier" &
The graph is viewable and displays my information I want, I just cannot figure out how to allow it to zoom in and out. I read that it has something to do with the X11 window no longer being set or that I need to set it via the command line, I just cannot figure out exactly how to, or if this is even the reason. Hopefully there are a couple GNUPLOT experts that can assist me. :)
Thank you.

Zooming and unzooming isn't possible in interactive windows which are left open with the -persist flag. Those operations would require a redrawing which isn't possible anymore since the main programs has already exited.
Quoting from the persist documentation:
[...] gnuplot will open a display window, draw the plot into it, and then exit, leaving the display window containing
the plot on the screen. Depending on the terminal type, some mousing operations may still be possible in
the persistent window. However operations like zoom/unzoom that require redrawing the plot are generally
not possible because the main program has already exited

You could add pause -1 at the end of the command list:
gnuplot -e "plot sin(x); pause -1" &

Related

Script to launch gnuplot and plot graph

I am trying to launch gnuplot and plot the graph for me with a single command. My script looks like this:
gnuplot
load "runscript"
But it would ignore the second command. Any help would be appreciated,Thanks.
I think that is no necessary to create another script to launch Gnuplot and then load your plotting script. This task is easy to be done using the Gnuplot commands. For example, consider you have a script called "test.gp" and its contents are:
set xlabel "Time t"
set ylabel "sin(t)"
set title 'Gnuplot test with PDFcairo'
plot [0:2*pi] sin(x) with lines lw 2 title 'Sin(x)'
Then, to run your "tes.gp" script just go to the folder that contains the file, and type in the command line:
gnuplot -p test.gp
the '-p' option allows the persist mode and remains the plot window.

gnuplot converting time to scientific notation

I have this program that grabs a lot of usage details regarding your computer and plots everything on a nice graph (below). The issue I am running into is that in the bottom left corner of the gnuplot window where it would normally report where on the (x,y) axis your mouse is currently at, it is reporting my x-axis in scientific notation.
For example, instead of stating that my mouse is at (33:10,20%) it is reporting that it is as (5.10770e+08,20%) <--Random scientific notation). I have already set the timefmt and xdata, so I am confused at to what I am missing in order to properly report the data. If someone could please help it would be greatly appreciated.
I have searched on superuser and Unix/Linux, and this question seems to fit on Stackoverflow the best as gnuplot has its own scripting language. Also if you look at the gnuplot tag on the various sites, gnuplot fits more on stackoverflow and has thousands of more tags compared to 30 and 67.
I have also viewed Turn Off Scientific Notation In Gnuplot and tried to implement the answer here (Christoph is the GNUPLOT man!), but have thus far been unable to configure it to work properly (it still displays the scientific notation).
gnuplot -e persist "set title 'Resource monitor' ; set timefmt '%y/%m/%d-%H:%M:%S' ; set xdata time ; set xlabel 'TIME' ; set ylabel 'PERCENT' set yrange [0:101]" -e "plot '${cpuResFile}' using 1:2 title 'CPU' smooth Bezier, '${memResFile}' using 1:2 title 'MEM' smooth Bezier ; pause -1"
You're in the right place to ask for gnuplot help!
I've tried this on x11 and wxt, don't know other interactive terminals.
You can switch between different mouse statusbar formats by pressing 1 (2 cycle backwards)
Fore more help on interactivity, press h and you'll get a list ho keyboard shortcuts
Some information is on help mouse format
To change it programmatically with the corresponding command set mouse format (but I didn't manage to display properly date/time...)

gnuplot wxt not working anymore

I have recently upgraded to Debian jessie, meaning that I have upgraded from gnuplot 4.6.0 to gnuplot 4.6.6 (issue is the same with gnuplot 5.0).
I have bash scripts automating things, and launching gnuplot terminal.
I was using either:
gnuplot -persist -e "set title 'Sine curve'; plot sin(x)"
or
gnuplot -persist <<EOF
set title 'Sine curve'
plot sin(x)
EOF
The terminal wxt is no more distributed by debian (and derivatives like ubuntu), because of #751441.
I am using now terminal qt. It displays the plot, but that's the end. The window is static and most of the buttons do not work. I cannot zoom, I cannot unzoom, I cannot show the grid.
How to circumvent this?
Answering my own question: I spent two much time googling, trying to understand why, reading excuses to not correct it, and finding workarounds.
First, you have to remove -persist because it has a wxt special way of working, and it is not the same way of working with qt terminal. See #1418.
Second, you have to add "pause mouse close" after your plot. See #1418. The script is now:
gnuplot -e "set title 'Sine curve'; plot sin(x); pause mouse close"
Now the zoom in, zoom out, and show grid are working.
Third, wait, you did not plotted a sinus, but with lines. Like this example:
$ gnuplot <<EOF
plot '-' using 1:2 t '' with line
0 0
10 10
e
pause mouse close
EOF
Now, if you zoom somewhere in the middle of a segment, you get nothing, an empty and blank screen. What you need is set clip two that tells to not clip when segments ends are not shown. See #1419. So the following will work:
$ gnuplot <<EOF
set clip two
plot '-' using 1:2 t '' with line
0 0
10 10
e
pause mouse close
EOF
Finally, what I have done, is:
add pause mouse close at the end of the script
add set clip two in ~/.gnuplot file
With this, I can mimic the wxt way of working while using qt terminal. IMHO, as a basic end-user, this should be the default.

Keep Gnuplot auto refresh window inactive

I am running a simple script, that reads data from a file and plots it. My problem is that I reread and replot the data, as the file continuously changes. Whenever I use refresh the plot window becomes active again, which I would like to prevent. I would like the plot to be updated in the background. Is this possible?
My sample script:
#!/usr/bin/gnuplot
set datafile separator ","
plot "data.dat" using 1:3
pause 1; refresh; reread;
This depends on what terminal you're using. wxt, x11 and qt support a noraise option:
set term x11 1 noraise
This should allow it to stay in the background.

gnuplot multiple graphs are not interactive

I am drawing multiple graphs via a shell script in gnuplot.
The graphs are drawn correctly, but am not am able to zoom in . Does any variable need to be set?
Here is the code:
--- for loop of script starts---
gnuplot -persist <<EOF
set term x11 1
set title "IP : $ip Upstream capacity:$UP_CAP kbps"
plot 'trace-0-dir1.txt' using (\$1-$min1):(\$2-\$1-$mindelay1) with lp
set term x11 2
set title "IP: $ip Downstream capacity:$DOWN_CAP kbps"
plot 'trace-0-dir2.txt' using (\$1-$min2):(\$2-\$1-$mindelay2) with lp
EOF
---for loop ends---
Once you switch away from the "x11 1" window the zooming is disabled. To regain control, you should switch back to the specific window (set term x11 1). Another issue is the x11 terminal. You should use wxt which can keep windows alive.
You can solve your issue by using the wxt terminal and separating the two plot commands, therefore not switching away from the window:
--- for loop of script starts---
gnuplot -persist <<EOF
set term wxt
set title "first"
plot x
EOF
gnuplot -persist <<EOF
set term wxt
set title "second"
plot x**2
EOF
---for loop ends---
With this, you have two zoomable windows open and you can still use your shell variables.
In general, you do not have to have console open in order to have active windows, just an appropriate terminal. Especially, the command
gnuplot --persist -e 'plot[0:10] sqrt(x)'
produces scrollable and zoomable windows if used with wxt. Try
gnuplot --persist -e 'set term wxt; plot[0:10] sqrt(x)'
Hope this helps.
AFAIK you are only able to zoom, scroll etc. if the gnuplot console is still active. Meaning, gnuplot must still be running.
To give zooming and scrolling a try, input the following sequence:
Enter the gnuplot console by typing gnuplot
plot a function with plot[0:10] sqrt(x) for example.
Try zooming (Ctrl + Mouse wheel) and scrolling (Mouse wheel / Shift + Mouse wheel) before exiting the gnuplot console.
If you run a script like
gnuplot --persist -e 'plot[0:10] sqrt(x)'
you cannot scroll or zoom anymore.

Resources