13

I am plotting graphs in gnuplot and would like to open them in full screen and a particular size.

Previously, I have been outputting graphs in multiplot mode and updating them using reread; so, when I maximise it manually, the plots fill the screen after a few iterations. Now, I also want to save the output as a file. When I open that file, it is in the same small size as the original multiplot output. However, when I maximise it, the plots don't increase in size to fill the screen. I have 2 questions:

  1. How can I open the multiplot file in full screen?
  2. How can I make the output file a particular size?

Here is my current gnuplot code (in a file called gnuplotCode):

set terminal pngcairo dashed enhanced
set output 'foo.png'
set multiplot layout 3, 3
plot for [iter=1:9] path/to/file using 1:(column(iter)) notitle
unset multiplot
unset output
pause 10
reread

I have tried to type the following:

gnuplot -geometry -3360-1050 gnuplotCode    # where my screen size is 3360x1050

and:

resolution=$(xrandr | grep '*') && resolution=${resolution%  *}
gnuplot -geometry $resolution gnuplotCode

but neither approach works. Please can you tell me how to open gnuplots in full screen and a particular size? Thank you.

Shenan
  • 425
  • 2
  • 9
  • 20
  • @Christoph, I inserted your code at the top of my code but I got an error message on the line `set terminal pngcairo size @monitorSize`: set terminal pngcairo size 1680,1050 unrecognized terminal option. pngcairo is an available terminal on my computer. Do you know why I get this error message? Thanks. – Shenan Aug 21 '14 at 09:35
  • @Christoph: If, instead, I replace `@monitorSize` with `1680,1050` it works fine. Could the problem be to do with `set macros`? Thank you. – Shenan Aug 21 '14 at 11:02
  • You need to use `set macros`, so that the content of the `monitorSize` variable is inserted in the command before this is evaluated. Do my two minimal examples work for you? I tested that they work with versions 4.4.4, 4.6.5 and 5.0rc1. – Christoph Aug 22 '14 at 18:38
  • @Christoph, I tried both of your examples and, in both cases, I got an error message on the line `set terminal pngcairo size @monitorSize`. The error message said: set terminal pngcairo size 1680,1050 1680,1050 ^ (after the end of the first line) "gnuplotCode", line 2 (or 3 - depending on the example): unrecognized terminal option. I use gnuplot version 4.6 patch level 5. – Shenan Aug 27 '14 at 09:19
  • Seems like the variable `monitorSize` contains some garbage besides the actual size. What does `print sprintf("--%s--", monitorSize)` give you? – Christoph Aug 27 '14 at 09:34
  • @Christoph, it gives me: undefined variable: monitorSize – Shenan Aug 27 '14 at 10:07
  • OK, I edited my answer (added list items) to ease discussions. If the script given under point 2 doesn't work, please add the line `print sprintf("--%s--", monitorSize)` as *second* line to see if the shell command works properly and extracts the correct size. The output should be `--1680,1050--`. – Christoph Aug 27 '14 at 10:39
  • @Christoph, the output is `--1680,1050` `1680,1050--` followed by the previous error (now) at line 4. – Shenan Aug 27 '14 at 13:54
  • Ok, then the current `system` command doesn't work for you. Can you try to use `monitorSize=system("xrandr | grep '*' | awk '{print $1}' | tr 'x' ','")` instead. This was what I had first, without the awk optimization. Otherwise I'll have to check later on my Linux box what might go wrong. – Christoph Aug 27 '14 at 13:57
  • @Christoph, the output is the same as with the previous `system` command. – Shenan Aug 27 '14 at 14:04
  • Ah, by change now I probably found the reason: If you have two monitors connected, the system command prints the resolution of both monitors. To get only the resolution of the first one, you can exit awk after the first match was found: `monitorSize=system("xrandr | awk '/\*/{sub(/x/,\",\");print $1; exit}'")`. – Christoph Aug 27 '14 at 20:03
  • Great. I updated my answer, so that the script doesn't crash for multi-monitor setups. – Christoph Aug 28 '14 at 09:20
  • http://superuser.com/questions/441035/how-to-make-gnuplots-fullscreen – Ciro Santilli OurBigBook.com Oct 09 '15 at 08:40

1 Answers1

11

You must distinguish between pixel-based terminals (pngcairo, png, canvas (...) and all interactive terminals wxt, x11, qt, windows, aqua, where the size is given in pixel. For vector-based terminals (postscript, svg, postscript etc) the size is given in inch or centimeters.

Using the -geometry flag works only for the x11 terminal:

gnuplot -geometry 800x800 -persist -e 'set terminal x11; plot x'

For all other pixel-based terminal you can use the size option to set the canvas size in pixel:

set terminal pngcairo size 800,800

Of course you can also extract the monitor resolution and use that as size. Here you have two variants:

  1. Extract the monitor size on the shell:

    monitorSize=$(xrandr | awk '/\*/{sub(/x/,",");print $1; exit}')
    gnuplot -e "monitorSize='$monitorSize'; load 'gnuplotCode'"
    

    The file gnuplotCode must then use the gnuplot variable monitorSize as follows:

    set macros
    set terminal pngcairo size @monitorSize
    set output 'foo.png'
    plot x
    

    Note, that the content of the string variable monitorSize must be used as macro, i.e. the value is inserted before the whole line is evaluated.

  2. If you don't want to have that additional line on the shell, you could also call the xrand stuff from within the gnuplot script via the system function. In that case the file gnuplotCode would look as follows:

    monitorSize=system("xrandr | awk '/\*/{sub(/x/,\",\");print $1; exit}'")
    set macros
    set terminal pngcairo size @monitorSize
    set output 'foobar.png'
    plot x**2
    

    which you must call only with gnuplot gnuplotCode.

Note, that the shell command as is always extracts the information of the first monitor only.

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • +1 `xrandr | awk '/\*/{sub(/x/,",");print $1}'` uses built-in awk functionality to do the same thing as what you've got but saves on pipes :) – Tom Fenech Aug 20 '14 at 17:57
  • 1
    @TomFenech Thanks once again for a nice awk improvement! – Christoph Aug 20 '14 at 18:19
  • @Christoph, variant #2 of your answer no longer works on my computer, though variant #1 still works. I get the error message: awk: line 1: regular expression compile failed (missing operand) * Do you know why? – Shenan Sep 28 '17 at 14:38
  • For me variant 2 still works, tested right now with GNU awk 4.1.4. – Christoph Sep 30 '17 at 13:04
  • Thank you, @Christoph. You led me to check my version of awk and I was using mawk not gawk. Installed gawk and it works now. – Shenan Oct 31 '17 at 16:56