Gnuplot : How to specify the graph width in pixels? - gnuplot

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

Related

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

Complex layout in gnuplot: mixing text and graphs

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.

Column and row name formatting in gnuplot

I prepared a code to graph my script's csv output. They are column separated values.
I used code below to do that:
#!/usr/bin/gnuplot -persist
set datafile separator ":"
set terminal png nocrop font small size 640,480
set output 'mychart.png'
set style data histograms
set title "some graph title"
set xlabel "some x asis name"
set ylabel "some ya axis name"
plot "/home/username/Desktop/test.csv" using 2:xticlabels(1) notitle
This will draw the graph successfully. However I have two problems here. One in x axis, there are big numerical values such as 50000000, 6000000 so graph shows them in exponential format such as 5E+9 6E+8. But I would like to see full number. Second, in y axis, there are almost 20 alphanumeric values (some network parameter names) and each of them with at least 25-30 character. So they won't show up properly. Is there a way to write them with a smaller font and an angle?
Thanks
To change the format of the numbers shown on the y-axis, use e.g.
set format y '%.0f'
The labels of the xtics can be rotated (rotate by 45), aligned differently (right) and they can use a different font size (font), e.g.
set xtics right rotate by 45 font ',8'
See also rotating and justifying tics in gnuplot.
You may need to adjust the bottom border to have enough space for the labels, e.g. with
set bmargin 6
BTW: You should use the pngcairo terminal (available since version 4.4), which produced much nicer graphs than the png terminal.

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.

Displace z-axis with gnuplot

Is it possible to displace the z-axis to the middle of the x-axis with gnuplot?
I've found a great gnuplot script here which nearly fits my needs perfectly, except that the z-axis should be going up at the middle of the x-axis.
by default gnuplot draws a border and places the labels on this border.
Draw only a border at the bottom, i.e around (x,y)-Plane :
set border 1+2+3+4
or disable it completely:
set border 0
draw a zaxis through the x,y-origin, and place the ztics on the same:
set zzeroaxis lt -1
set ztics axis
same for x and y, if you like.

Resources