Complex layout in gnuplot: mixing text and graphs - gnuplot

I am considering if is feasible to use Gnuplot for my needs. And since I have little experience with it, I need to ask to more knowledgeable persons.
I need basically to visualize data coming from different datasets; but it can't be merged on a single plot. Also I need to add text, to display certain values, which I cannot display as legend or on top of the plot, to not cause confusion.
What I would like to do, is to make something similar to what you see in Xcode Instruments: a grid view with stacked graphs, where each graph does not occupy the whole portion of the plot, but just part of it, and then I can put text on the sides of the plot, in specific sections.
Something like this, to give you a visual (not exactly the same of course):
https://developer.apple.com/library/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/art/Instruments_2x.png
I was checking the examples, and was able to ad a plot with a dot at a specific place; which help me to identify specific values on each plot, using
set object circle
I have found a way to stack the graphs, with
set multi plot layout
But I can't find an easy way to also resize the plot, so I can make room on left and right sides, to put some text in it.
Any suggestion is more than welcome...I don't even know if Gnuplot is in fact the best tool for the job. I will put the plot images on reports and on our intranet.

set multiplot and then changing the margins let you freely modify the position of all your graphs and customize the distance between them. If you want four graphs on top of each other similar to what you showed in the link, you could do something like the following:
set multiplot
set lmargin at screen 0.2 # Sets left margin at 0.2 from left end
set rmargin at screen 0.9 # Sets right margin at 0.9 from left end
set tmargin at screen 0.9 # Sets top margin at 0.9 from bottom
set bmargin at screen 0.7 # Sets bottom margin at 0.2 from bottom
set format x '' # Remove numbers along x axis
plot sin(x)
set tmargin at screen 0.7 # Sets top margin at 0.7 from bottom
set bmargin at screen 0.5 # Sets bottom margin at 0.5 from bottom
plot cos(x)
set tmargin at screen 0.5 # Sets top margin at 0.5 from bottom
set bmargin at screen 0.3 # Sets bottom margin at 0.3 from bottom
plot exp(x)
set tmargin at screen 0.3 # Sets top margin at 0.3 from bottom
set bmargin at screen 0.1 # Sets bottom margin at 0.1 from bottom
set format x # Restore numbers along x axis
plot x**2
And of course you can complicate this as much as you want.

Related

gnuplot multiplot - layout and scale

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?

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.

Gnuplot : How to specify the graph width in pixels?

I would like to plot the output of a dataset so that there is one pixel per sample, on the X axis. e.g. if I have a dataset of 500 samples then I would like to ensure that the X axis is 500 pixels wide. Does anyone know how to do this with Gnuplot ?
Thanks very much,
John
This request makes sense only for bitmap terminals. In order to get a plotting area with a fixed size, you must both set a respective terminal size and fixed margins. The following script gives a plotting area of 500px width. This includes the 1px thick border lines, which are also part of the plotting area, what you can see, with set border back:
set terminal pngcairo size 600,500
set lmargin at screen 80.0/600
set rmargin at screen 579.0/600
set border back
set output 'output.png'
plot x

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