how to overlay 2 graphs in a single plot in GNUplot - gnuplot

I have two files that has the time as x axis and a value. I need to overlay these two on a single plot. Currently i tried it using GNUplot, but struck in the middle. Here is a sample file
01:03:05 6
01:03:15 6
and another file
01:03:55 6
01:04:10 6
I need to plot these two files (say x mark and some other symbol for differentiation) in a single plot. I dont know if it is possible to do that in GNUplot. Currently I have created two grids for each file. But I need both in a single plot. Here is what I have written
set multiplot layout 1,2 # engage multiplot mode
set xdata time ## these three lines control how gnuplot
set timefmt '%H:%M:%S' ## reads and writes time-formatted data.
set format x '%H:%M:%S' ##
set xtics 05 # make time spacing of 2 minutes
plot 'AAA' u 1:2 # plot the first data set
plot 'BBB' u 1:2 # plot the second data set
unset multiplot
Can anyone familiar with GNUplot or any other tool (working in linux) can help me.

In order to plot multiple lines in a single plot, simply put them in a single plot command like
plot 'AAA' u 1:2, 'BBB' u 1:2
There are numerous examples out there that give you a good start with gnuplot. This one for example shows how to plot multiple lines in one plot.
The multiplot command you are using in your script would also make it possible to have multiple plot windows like shown here. You can adjust the position of each subplot by:
set size XSIZE,YSIZE #see `help set size`
set origin XORIGIN,YORIGIN #see `help set origin`
or (if you have gnuplot 4.2 or newer):
set lmargin at screen XMIN #see `help margin`
set rmargin at screen XMAX
set tmargin at screen YMAX
set bmargin at screen YMIN

Related

Gnuplot - Multiplot autoscale displays x-axis and y-axis units twice on each other

In Gnuplot I want to display 2 plots on the same graph with the help of multiplot. The display works fine, but the scaling redisplays and the same units are put on each other, because i use autoscale.
My question is, how do i display the scaling only once?
Here is my code:
set border 1023-128
set autoscale
set multiplot
plot strDsDir.strInputFile using 1:($6/1000000) skip 1 w filledcurves x lc rgb "#00aa22"
replot strDsDir.strInputFile using 1:($7/1000000) skip 1 w filledcurves x lc rgb "#80e45f"
unset multiplot
I tried unsetting autoscale, between the "plot" and "replot", but then I lose autoscaling, and graphs slip.
I also tried unsetting xtics and ytics, but then i lose the set border 1023-128 above.
Here is the picture, where my units lapse on eachother :
And here is the picture, where units dont lapse on each other, but my "set border option" disappears :
The dataset what im trying to display doesnt matter.
Thank you.
The purpose of multiplot usually is to plot several plots beside each other. If you want to plot several curves in a single plot, use a single plot command like plot x, x**2:
plot strDsDir.strInputFile using 1:($6/1e6) skip 1 w filledcurves x lc rgb "#00aa22", \
"" using 1:($7/1e6) skip 1 w filledcurves x lc rgb "#80e45f"

Manual scaling of axis (poltting with boxes) in gnuplot

I'm trying to plot a really long list, which represents frequency of some data. The x axis goes from 1 to 1881, and the y goes from 1 to 1978. I tried plotting with the following configurations:
set log y 5
set log x 32
set xtics 2
set ytics 5
plot "freq.dat" w boxes
But i get the following result:
Which is clearly not good because there are these intersections of the boxes. I want to have some kind of scale that have a lot more space between 10 and 150 than the outside of this area. How can i do that? I've tried every combination of logs and xtics and couldn't make it look good. The y axis seems good to me, the only problem is the spacing of x-axis.
Also, i want to know how to do this in gnuplot specifically (if possible).
Thanks.
It seems to me that your script overrides somewhere the default boxwidth. The default behavior is:
By default, adjacent boxes are extended in width until they touch
each other. A different default width may be specified using the set boxwidth command. Relative widths are interpreted as being a
fraction of this default width.
So for example this:
set terminal pngcairo enhanced
set output 'fig.png'
set log x 2
set log y 5
set yr [0.2:3125]
set xr [1:512]
set boxwidth 1 relative
set xtics 1,2,512 out nomirror
set ytics 1,5,3125 out nomirror
unset key
#set style fill pattern 6
plot 'freq.dat' w boxes lc rgb 'royalblue' lw 1.1
then yields:

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

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.

Output gnuplot legend in separate file [duplicate]

I have an interactive perl script which uses data from mysql to generate many plots through the Chart::Gnuplot package. There are times when the graph size is overloaded with too many plots.
I would option to generate the gnuplot image containing only the legend (no graph).
I don't know if this would help, but...
plot [0:1] [0:1] NaN title "Hello" #Just the label in the legend.
or...
plot sin(x),NaN title "Boo" #Plots sin(x) (properly labelled) and a second label "Boo"
Of course, this still has the border and other things. You can unset those...unset border and unset tics

Resources