How to get circles with specific radii in pixels in gnuplot - gnuplot

When plotting data using circles, the radii of the circles depend on the data size (i.e. X/Y ranges) according to the answers for the question in Gnuplot: plot with circles of a defined radius .
Is it possible to define a screen delimited radii for the circles instead? That is, I want all the circles to have a specific radius in pixels no matter they size nor the X/Y ranges.

So you are just looking for a plot symbol in the shape of a circle? Then use the usual points style with pointtype 6 (empty circles) or 7 (solid circles), and specify the pointsize scale factor (1 corresponds to default)
plot [0:2] '+' using 1:1 with points pointtype 6 pointsize 1, \
'+' using 1:(sqrt($1)) with points pointsize 1.5 pointtype 7

Related

What is the best way to fill large region in gnuplot with transparent color?

I'm trying to plot my result from verification with gnuplot. Now I am trying to draw unsafe region for this picture. The imagine shows below. Suppose unsafe set is x > 3, then everything above x = 3 should be filled with transparent colour to indicate it is an unsafe region. I am new to gnuplot, and I am thinking to draw a large rectangle with transparent colour, but is there a better way to achieve this in gnuplot? Thank you.
Yes, drawing a rectangle is a good option for your use case:
set object rectangle from graph 0, first 3 to graph 1, graph 1 fillcolor rgb 'red' fillstyle transparent solid 0.5 noborder
plot ...
Using the graph coordinates makes three borders of your rectangle independent of the axes ranges.

How can I plot a smoothed curve as well as the original data?

I want to add markers to some of my plots using pointtype. If I plot data like so:
plot "somedata.txt" w linespoint pointtype 6
or a function like so:
plot cos(x) pointtype 6
I get exactly what I want: a line between and a marker on top of all data points. Right now I want to achieve the same, but after "smoothing" out a dataset using smooth bezier:
plot "somedata.txt" w linespoint pointtype 6 smooth bezier
However pointtype doesn't seem to do anything. I can set linecolor, linewidth and linetype as before, but not pointtype.
Does anyone know of a work-around that can still produce markers on top of a smoothed plot?
I have the same issue that gnuplot does not plot points on top of a smooth curve. I speculate that since gnuplot is plotting a function derived from the data points, it does not bother putting the point markers on top of the original data points
Note that a bezier curve will not necessarily overlay the original data points.
My workaround would involve plotting the data twice in different ways:
plot 'data.txt' with points title 'original data', \
'' smooth bezier title 'smoothed data'
I agree with #andyras. I have this issue a few weeks algo and couldn't find a way to put both, the smoothed curve and the data. Thus, I plotted two series, one with the smoothed curve and another just for the points.
Edit: sorry for adding a new answer. I'm on my phone and couldn't find a way to comment under #andyras answer

How do I use a data parameter to set the colour of gnuplot points?

I'm creating a GIF of the movement of random particles and I want to plot the particles as points of a certain colour that relates to the velocity of the particle at a given time. Using gnuplot 4.6.6, how do I make the colour of a point a function of a data value? If possible, I'd like the colours to come from the palette 'rgbformula 21,22,23' and not just from the standard line colours set.
Thanks
You can use the lc palette flag:
set palette rgbformulae 21,22,23
plot 'particles.dat' using 1:2:3 lc palette
type ? linecolor or ? palette for more info.
You can pass a third column to the plot command and linecolor palette. Then, the palette colors are used to encode the value of the third column and the colorbox showing the palette is drawn:
set palette rgbformula 21,22,23
plot "data" using 1:2:3 with points linecolor palette

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.

How to change dot size in gnuplot

How to change point size and shape and color in gnuplot.
plot "./points.dat" using 1:2 title with dots
I am using above command to plot graph ,but it shows very small size points.
I tried to use command
set pointsize 20
but still point size is same.
Use the pointtype and pointsize options, e.g.
plot "./points.dat" using 1:2 pt 7 ps 10
where pt 7 gives you a filled circle and ps 10 is the size.
See: Plotting data.
The pointsize command scales the size of points, but does not affect the size of dots.
In other words, plot ... with points ps 2 will generate points of twice the normal size, but for plot ... with dots ps 2 the "ps 2" part is ignored.
You could use circular points (pt 7), which look just like dots.
plot "./points.dat" using 1:2 title with dt 2 lw 4

Resources