gnuplot multiplot - layout and scale - layout

Multiplot scale
I don't really understand the idea behind the scale option in the multiplot command of gnuplot.
set multiplot layout 2,2 scale x,y
There can be only one pair of values for the whole multiplot - what is it possibly used for? Is it really just for scaling all the graphs in the multiplot? What for?
It would make sense to me, if you could assign scale factors the the individual layout parts, in that I would say: first column takes 70% of the width, second column takes 30% etc but here?
I'd appreciate any explanation! Plus, is there a built-in function to generate multiplots using the "layout" option in the described manner?
Multiplot Layout
I want a multiplot layout consisting of a 4rows,2columns grid. Both columns should fill 45% of the space each, leaving a 10% white gap at the right which will be used for a label set right next to the second column via set label at graph 1,0.5 "text". (Actually, this means a 45% / 55% ratio of the two columns.)
This works with this MWE
set multiplot
mystring = "This is\na multiline\nlabel"
width = 0.45
height = 0.25
#1 1
set origin 0,1-height
set size width,height #remains the same
plot sin(x)
#1 2
set origin width,1-height
set label at graph 1,0.5 offset 2,1 mystring
plot cos(x)
unset label
#2 1
set origin 0,1-2*height
plot sin(x*2)
#2 2
set origin width,1-2*height
mystring = "This "This is\na different\nlabel"
set label at graph 1,0.5 offset 2,1 mystring
plot cos(x)
unset label
#etc...
unset multiplot
However, I want to put some labels (no title etc) above the first row. If I make space via set tmargin <val> for the first row, then the plots get squished, not shifted. Is there a way to somehow "add whitespace" around the plots, the top in particular? Or would I need to make the height variable a tad smaller and adjust accordingly?
Plus, I made no size settings, as you see, but used proportionals in the range of [0,1]. When using the epslatex terminal, I'll provide overall size information. Can I expect the ratios to preserve?

Related

Modifying the margin alignment in gnuplot in multiplot mode

I have created two plots in multiplot mode using epslatex as output terminal. The y axis labeling is different for both the plots.The first plot's y axis ranges from [0:45] and the second plot's y-axis ranges from [-5e-008 to 4e-007]. Due to the different widths of the y-axis labels, the width of the second plot is less than that of the first plot. I have tried the available scaling options but they do not work. Is it possible to edit the plot so that I can have the same width for both the plots irrespective of the y-axis range?
The problem you're experiencing can be reproduced by doing something like so:
set multiplot layout 2,1
plot sin(x)
plot 100000*sin(x)
The left margins are clearly not aligned. To fix this, you can try an explicit definition of where the margins lie:
set multiplot layout 2,1
set lmargin at screen 0.15
plot sin(x)
plot 100000*sin(x)
If your images are side by side, you can adjust the margins taking the appropriate offset into account:
set multiplot layout 1,2
set lmargin at screen 0.15
plot sin(x)
set lmargin at screen 0.5+0.15
plot 100000*sin(x)

One big and two small plots in multiplot gnuplot

I am trying to plot three different plots on the same canvas using the multiplot mode of gnuplot (version 5.0.1)
I want an arrangement of these plots in a particular way: final plot should show 2 rows with plot A in the upper row while plots B and C should appear in the lower row side-by-side as if for a lower row we had something like:
"set multiplot layout 1,2"
How can this be achieved?
Thanks in advance
you need to do the multiplot with the most "refined" grid, in this case 2x2 and then specify the size of each plot.
set multiplot layout 2,2
set size 1,0.5 # the first one has to be larger
plot sin(1*x)
set multiplot next # we want to skip the second (upright position)
set size 0.5,0.5 # the second and third have to be 0.5x0.5
plot sin(2*x)
plot sin(3*5)
unset multiplot
or as suggested here https://stackoverflow.com/a/15906085/2743307 it might be simpler to do it upwards (6 lines instead of 8!) but you have to specify the plots in opposite order:
set multiplot layout 2,2 upwards
plot sin(3*x)
plot sin(2*x)
set size 1,0.5
plot sin(1*x)
unset multiplot

Multiplot for creating zoom charts

I want to use multiplot in a way that there is one big chart and one small chart. The small chart in the magnified version of the big chart. There is a good example here but my scales are different from the example and I found that setting the correct size and origin values very hard!
I want to draw something like this
The data file contains simple integer numbers like
10000
20300
12340
10
40000
...
The xrange is [0:4000000] and yrange is [0:4000000] I want to zoom X from 100000 to 300000
Hard thing for me is how to put the small chart in the right of the big chart? top or bottom doesn't matter.
UPDATE:
When I set the origin of the second chart to set origin 0.8,0.8, I see that the second chart is on top right, but the canvas doesn't scale correctly.
set origin 0.6, 0.6
set origin 0.8, 0.8
You can either use set size in combination with set origin to scale and shift your plots. Or you could use set lmargin etc. to control the size of the plots with respect to the image size (i.e. the canvas size). (Of course you could also combine those parameters)
Here is a sample script which uses only the size and the origin. The values given to set size are in screen coordinates. So set size 1,1 is the default and the plot area plus all margins corresponds to the canvas size. With set size 0.5,1 you scale the plot's to 50% of the canvas width. Also set origin uses this kind of coordinates.
Since you want to place both plots side-by-side, You can use an image size with a large aspect ratio (set terminal pdfcairo size 4in,2in).
set term pdfcairo size 4,2
set output 'foobar.pdf'
set multiplot
unset tics
set border 3
set origin 0,0
set size 0.8,1
plot x**2
set origin 0.75,0.2
set size 0.25,0.3
plot x
unset multiplot
You can find the answer in this post or in this another plot. The trick is to play with set size and set origin

adding space between x axis and xtics in gnuplot histogram

Currently I created graphs with small size. The spacing really important at this case. I want to add more vertical space between my xticlabels and x axis.
I have tried to set the x bar with
set xtics offset 0,graph 0.05
my gnuplot output:
The data and gnuplot script still same with my previous question here.
You can do the following:
First add a little bit of bmargin by
set bmargin 3
Since you need to add vertical space between your xticlabels and x-axis, you need to adjust the Y-offset, which can be done by the following
set xtics offset 0,-1,0
You can play around with the values to suite your need.

Creating a microphone polar pattern plot in gnuplot

I would like to create a microphone polar pattern plot that has a scale of -20 (in the center) out to +5 in steps of 5. I have found similar code but nothing that allows for the scales to be negative.
Multiple patterns will then need to added to the plot covering a few different frequencies, I have degree values (0-360) and corresponding dB values (-25 - +5).
This is what the plot should look like (though with slightly different scales):
The closest gnuplot I have found to this is here: How to get a radial(polar) plot using gnu plot?
Perhaps this could be modified to suit my needs?
I would also like 0 degrees to be found at the top of the plot rather than on the right.
I am new to using gnuplot so I am not particularly familiar with its code, therefore it has been difficult for me to modify the code with any great success (so far anyway).
So you want to plot a polar function, e.g. r(theta) = 1 + sin(theta).
Plotting the function is quite easy, just do
set polar
plot 1+sin(t)
A simple polar grid can be plotted with
set grid polar
but that has the raxis and the rtics on a different position than where you wanted. It is not problem to specify custom labels. But angular labels aren't supported, so you need to set them manually. And the border and the other axes and tics must be unset.
To get the very same image as you showed, use the following script:
set terminal pngcairo size 700,600 font ',10'
set output 'cardioid.png'
set angle degree
set polar
set size ratio 1
set tmargin 3
set bmargin 3
set style line 11 lc rgb 'gray80' lt -1
set grid polar ls 11
unset border
unset xtics
unset ytics
r=1
set rrange [0:r]
set rtics 0.166 format '' scale 0
set label '0°' center at first 0, first r*1.05
set label '180°' center at first 0, first -r*1.05
set label '90°' right at first -r*1.05, 0
set label '270°' left at first r*1.05, 0
set for [i=1:5] label at first r*0.02, first r*((i/6.0) + 0.03) sprintf("%d dB", -30+(i*5))
unset raxis
plot 0.5*(1+sin(t)) linewidth 2 t ''
With the result:
That includes some offsets for the labels, which depend on the terminal, the canvas size and the font size. So you may need to adapt them.
I had to increase the top and bottom margins a bit (here by 3 character heights) in order to have enough space for the angular labels. They aren't included in the automatic margin calculations, because the don't belong to an axis.
Unfortunately Christoph's answer is wrong.
You can see that if you check where the plot curve crosses the 5db circle.
What should be plotted is
20*log10(A+B*cos(t))
where A+B = 1 and A - B determines the (nominal) directivity pattern.
The first diagram seems to be for A=B=0.5 which makes for a cardioid pattern.

Resources