Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open gnuplots in full screen and a particular size?

Tags:

output

gnuplot

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.

like image 796
Shenan Avatar asked Aug 20 '14 15:08

Shenan


People also ask

How do I open a gnuplot file?

You can run a script two ways: Type load "scriptname" from within gnuplot. Or, from UNIX, run gnuplot by typing gnuplot scriptname . In this method, gnuplot will exit when your script is finished, so you may want to include PAUSE -1 "Hit any key to continue" as your last line.

Does gnuplot have a GUI?

There is also a graphical user interface (GUI) for gnuplot .

Is gnuplot better than Matplotlib?

Matplotlib = ease of use, Gnuplot = (slightly better) performance. I know this post is old and answered but I was passing by and wanted to put my two cents. Here is my conclusion: if you have a not-so-big data set, you should use Matplotlib. It's easier and looks better.

Does gnuplot support multiple Y axes on a single plot?

5.9 Does gnuplot support multiple y-axes on a single plot? Yes. 2D plots can have separate x axes at the bottom (x1) and top (x2), and separate y axes at the left (y1) and right (y2).


1 Answers

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.

like image 125
Christoph Avatar answered Oct 05 '22 23:10

Christoph