gnuplot: how to put two figures side by side - gnuplot

I'm trying to put two figures side by side using gnuplot with multiplot.
I want the resulting image to be rectangular so I use set size 2, 1. I also set the set multiplot layout 1, 2 option. However, the resulting image only uses the left part of the available space. Any help will be appreciated.
Thanks
Ahmet
Here is the resulting image
http://tinypic.com/r/33mlz04/6
And below is the gnuplot commands I'm using.
set terminal postscript eps color enhanced
set output 'figure.eps';
set size 2,1;
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
Although I'm not very sure, with some trial and error I have solved it
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1,0.5;
set multiplot layout 1, 2 ;
set title "Figure 1";
set size 0.5,0.5;
plot "data/data1.txt"
set title "Figure 1";
set size 0.5,0.5;
plot "data/data2.txt"
unset multiplot

Try something like:
set terminal postscript eps color enhanced size 10,5
set output 'figure.eps';
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
When you set the size on the terminal specification line, that determines the actual size of the plot canvas (in inches in this case). When you use set size on a separate line, that sets the size of the plot in relative units of the canvas size. This is different in older versions of gnuplot. For perhaps a better explanation, try help set size in gnuplot.

For even more control over the size/position of the plot, you can use set origin in conjuction with set size to change the placement and size of each plot. Finally, the most control can be achieved with set lmargin at <place> (and set rmargin ...) and so-on for tmargin and bmargin where the "lrtb" stand for left, right, top and bottom respectively.
So, to get a plot to fill all of the available space (left to right), you could:
set multiplot
set lmargin at 0
set rmargin at .5
plot sin(x)
set lmargin at .5
set rmargin at 1
plot cos(x)
unset multiplot
However, this is (usually) overkill. Usually gnuplot tries to make the margins big enough for your labels and such, but setting the margin explicitly disables that. I would suggest you go with the solution by andyras.

if you are having problems using this method for more than 2 figures add 'set origin 0,0' after 'set size 0.5,0.5'.
For example, for three figures :
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1.5,0.5;
set multiplot layout 1, 3 ;
set title "Figure 1";
set size 0.5,0.5;
set origin 0,0
plot "data/data1.txt"
set title "Figure 2";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
set title "Figure 3";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
unset multiplot

Related

Bars overlapping box area gnuplot

I have a histogram plot where the bars are simply too high that they overlap the box at the top right that displays information about each bar (what do you call this box?)
Currently it looks like this:
I'm been tring to change the size (height) of the canvas so that it is taller with set size but I couldn't get it to work. I then used yrange but I don't want to specify more range to solve this problem. I want it so that the inner canvas is more square and not rectangular (more height) without changing the range. How do I do this?
set term png
set output 'output.png'
red = "#FF0000";
green = "#00FF00";
blue = "#0000FF";
skyblue = "#87CEEB";
purple = "#4B0082";
set ylabel "Time (s)"
set xlabel "CPU"
set style data histogram
set style histogram cluster
set style fill solid
set boxwidth 0.9
set grid ytics
set xtics rotate
set title "Compiled with gcc/g++"
plot "processor.dat" using 2:xtic(1) title "-O1" linecolor rgb red, \
'' using 3 title "-O2" linecolor rgb blue, \
'' using 4 title "-O3" linecolor rgb green, \
'' using 5 title "-Os" linecolor rgb skyblue, \
'' using 6 title "-Ofast" linecolor rgb purple
The "box" is called "key". In the gnuplot command line, help set key explains its options. You can move it to the empty left upper corner with
set key left
To increase the height of the picture I would change the overall size of the png like this:
set terminal png size 640,640
On my system, your command set term png defaults to set terminal png size 640,480.
To make the plot area an exact square, the following command is used:
set size ratio 1
This is the result with some fake data:

Changing ytic font size in gnuplot epslatex (multiplot)

I have problems changing the font size of my ytics (xtics as well) in an epslatex gnuplot.
I tried set format y '\tiny{%g}'
It is only working for the first of the two plots.
This is my code:
set terminal epslatex
set output "w_alt_nsyB_multi.tex"
set multiplot layout 1,1
set xrange [-0.5:17]
set yrange [0:110]
set xlabel "days"
set ylabel "Survival (\\%)" offset 2.5
set key reverse
set xtics font 'Arial,4' s
et style histogram errorbars gap 2 lw 1
set style data histogram
set style fill solid 1 border lt -1
set boxwidth 0.8
plot 'w_alt_nsyB.dat' every ::::7 using 2:3:xticlabels(1) title 'w1118' lt rgb "#000000",\
'w_alt_nsyB.dat' every ::::7 using 4:5 title 'wtSYN' lt rgb "#FF0000",\
'w_alt_elav_endoG.dat' every ::::7 using 6:7 title '38085' lt rgb "#9400D3"
set origin 0.5, 0.25
set size 0.5, 0.5
set xrange [-0.5:6]
set yrange [0:110]
set xlabel "\\tiny{Time of $Mn^{2+}$ treatment}"
set ytics ('10'10,'50'50,'100'100) nomirror
unset border
set xtics nomirror
unset ylabel
unset key
plot 'w_alt_nsyB_100.dat' using 2:3:xticlabels(1) lt rgb "#000000",\
'w_alt_nsyB_100.dat' using 4:5:xticlabels(1) lt rgb "#FF0000",\
'w_alt_nsyB_100.dat' using 6:7:xticlabels(1) lt rgb "#9400D3"
unset multiplot
Can anyone help me please?
The format given in set format ... isn't applied if you give an explicit manual label like you do with
set ytics ('10'10,'50'50,'100'100)
You must either just give the locations of the labels
set format y '\tiny %g'
set ytics (10, 50, 100)
or include the font macro in every manual label
set ytics ('\tiny 10' 10, '\tiny 50' 50, '\tiny 100' 100)
Note also, that your syntax \tiny{%g} is wrong, \tiny is only a switch and doesn't take any arguments. In this case it doesn't matter, because every label is wrapped in an individual LaTeX box, but in other situations it makes a big difference. To wrap the tiny font you would usually need {\tiny %g}.
The same happens for the explicit labels which are set with xticlabel. Also here, the format from set format x doesn't apply. Instead of giving a column number to xticlabel (like xticlabel(1) in your example), you must give the complete label string including the macro:
xl(c) = sprintf('\tiny %s', strcol(c))
plot 'file.dat' using 2:3:xticlabel(xl(1))
Next time, please give a minimal example which allows others to reproduce your problem. We don't have your data files to run the script. And your problem isn't related to you specific data file, so you can as well construct an example using functions, which possibly leads you itself to the solution...

undefined variable: GPVAL_DATA_Y_MIN (Gnuplot)

Based on this post (I am using gnuplot gnuplot 4.6 patchlevel 1):
gnuplot: max and min values in a range
I am trying to use set yr [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX] in my .pg script that plots data from this .dat file:
100 2
200 4
300 9
But I get:
undefined variable: GPVAL_DATA_Y_MIN
This is my script:
set terminal png
set output 'img.png'
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5
set style fill solid
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
plot 'sample.dat' with boxes title ""
Any ideas?
The gnuplot-defined variables are available only after a plot command (In the question you linked to, a replot is used to plot again).
Basically you have different options:
First plot to terminal unknown, and then change to the real terminal, set the range (now the variables are available), and replot:
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5 relative
set style fill solid
set terminal unknown
plot 'sample.dat' with boxes title ""
set terminal pngcairo
set output 'img.png'
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
Note, that I used the pngcairo terminal, which gives much better results, than the png terminal. And I used set boxwidth 0.5 relative.
Use set autoscale to fix the ranges instead of setting an explicit yrange. You can use set offset to specify a margin based on the autoscaled values:
set autoscale yfix
# set offset 0,0,0.5,0.5
plot 'sample.dat' with boxes title ''
Use the stats command to extract the minimum and maximum values:
stats 'sample.dat' using 1:2
set yrange[STATS_min_y:STATS_max_y]
plot 'sample.dat' with boxes title ''

Is it possible to plot 2 graphs in multiplot in gnuplot, with -persist flag?

I want to do something like that:
gnuplot_script.gp :
reset
set term x11 persist
set grid
set size 1,1
set multiplot
i = 0
while (i < 5) {
set size 0.5,0.5
set origin 0,0.5
plot i*sin(x)
set size 0.5,0.5
set origin 0.5,0.5
plot i*cos(x)
pause 0.5
i = i + 1
}
unset multiplot
I wish to see it animated, but everything just being smeared on the screen...
Is there any other way to do it ?
Thanks
I solved it...
If you put the "set unset" inside the "while" loop, it works

Placing label over mapped 3D graph in Gnuplot

I want the below desired effect
I am using a gnuplot script similar to this
reset
set term postscript eps enhanced "Helvetica" 30
set size square
set xlabel "X position"
set ylabel "Y position"
set pm3d map
set palette rgbformulae 22,13,-31
set xrange [0 : 22.0000000000]
set yrange [0 : 17.0000000000]
set zrange [0 : 0.1614027105]
set xtics 5
set ytics 0,4
set cbtics 0,0.020
set style line 1 lw 1
unset key
set dgrid3d 45,45
set style line 1 lt 1
set hidden3d
splot "data.data" u 1:2:3
set label "98.8" at 9,-2 textcolor lt 1
set label "1.2" at 9,6 textcolor lt 1
But when I do, the labels (98.8, and 1.2) don't get printed. If I provide a bogus data.data file, lets say with only a single (x,y,z) point, then nothing gets graphed and I can see the labels. Therefore, I am guessing that my graph is occluding my labels. How do I get the labels to be printed on top of my graph?
The default placement for labels is in back.
But you can specify that the label show up in front, e.g.:
set label "label in front" at 2.5,0.5 tc rgb "white" font ",30" front
Credit: the (very slightly modified) code for this was found at http://gnuplot.sourceforge.net/demo_svg_4.5/pm3dcolors.html and/or link(s) therefrom.
Also for further information on the placement of text in gnuplot, I found this reference to be very useful.

Resources