Gnuplot: arc circles with no line - gnuplot

I am trying to plot an arc segment using Gnuplot this circle command:
set obj 1 circle at 9 size 3 arc [0:180] fc rgb "blue" lw 1
And I'm getting
But I would like to get
Is there a simple way to do that? Or do I need to draw the arc and then "erase" the part I don't need?

I was looking for the same function, but it seems that gnuplot doesn't support such features. Moreover, sometimes you need to plot such an arc using a non-polar plot and that doesn't make your life easier.
Nevertheless, gnuplot allows you to do some tricks.
You can always set an arc and use any pair of angles you need.
Next, you simply reverse the order of angles so that your initial one becomes your final and vice versa. Also, the colour has to be white.
set object 2 circle at 1.5, 0.8 arc [-90:90] size 1 fc rgb "black" lw 4
set object 3 circle at 1.5, 0.8 arc [90:-90] size 1 fc rgb "white" lw 4
In addition, when you work with vectorized images, it's better to make the second arc a bit thicker, say, lw 5, otherwise some minor artefacts are observed.

I think your only recourse is to plot a function, something like
set parametric
plot [-pi/2:pi/2] sin(t),cos(t)

Related

Gnuplot smooth curve through frequency points + filled area under curve

I am a gnuplot-newbie and am stuck with the following situation. Based on this I have a gnuplot script as follows:
clear
reset
set key off
set border 3
set style fill solid 1.0 noborder
bin_width = 0.01;
set boxwidth bin_width absolute
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
plot '1000randomValuesBetween0and1.dat' using (rounded($1)):(1) smooth frequency
Which was a good first step; but I would like to have a smooth curve through the points that are generated by counting the frequency. with filledcurves lacked what I wanted in 2 ways. First it is not smoothed (I would prefer something like bezier which is not usable after with); second the filling is done in a rather unexpected way which doesn't fit my needs (for me unexpected). See this picture .
To give a little bit more context: I ultimately want to use this to generate
violin plots with gnuplot without having to do the binning beforehand so I can just give my script a single-column data-file and am ready to go.
EDIT: I tried adapting the "normal" density plot from this demo as another first step, but I failed; I read in the documentation that bandwidth should be 1/#points so it
should be 0.001 in my case meaning I tried this:
set border 3 front lt black linewidth 1.000 dashtype solid
set style increment default
set style data filledcurves
set xtics border in scale 0,0 nomirror norotate autojustify
set xtics norangelimit 0.00000,0.5,1.0
set title "Same data - kernel density"
set title font ",15" norotate
plot 'random01.dat' using 1:(1) smooth kdensity bandwidth 0.001 with filledcurves above y lt 9
which results in this picture:.
Setting no bandwith or lower/higher values didn't solve the issue.
The plot specifies using 1:(1) because I just have a single column so according to the doc the first value should be this column and as the second value would specify a weighting which should be 1/#points according to doc.
EDIT2: Setting bandwidth to the ideal value or not setting it at all always yields the same result which doesn't change anything except the scale of the y-axis with changing the weighting.
My data are 1000 values in a range between 0 and 1 (created randomly for testing purposes).
Here the new plot
EDIT3: zooming out may show another aspect of the problem as the plot seems to extend outside the interval of the given values (I checked the values and there are no examples <0 or >1). Here's the graph:
The demo 'violinplot.dem' included with the gnuplot distribution package and also available online shows how to do what you want using the combination "smooth kdensity" and "with filledcurve" applied to unbinned data.
Online version here: violin plot demo
Notes:
You mis-read the documentation. 1/N is not the recommended bandwidth, it is the normalized uniform weight. The plot you showed initially looks like the bandwidth was set far too low. What is the range of values in your data?
I suggest letting the program calculate the "ideal" bandwidth for you and then adjusting it afterwards if you think it is too large. The ideal value is stored in GPVAL_KDENSITY_BANDWIDTH. Increasing the bandwidth will make the envelope smoother; decreasing it will emphasize local spikes.

Convex hull figure from vertice points

I would like to make convex hull figure giving Gnuplot the vertices that join the surfaces of the figure.
I have been testing, but I have not any clear way to make this.
I can plot the points with this script:
set encoding iso_8859_1
set terminal postscript eps enhanced color size 4.0in,4.0in #"Helvetica" 16
set output "RG1.eps"
set view 50,220
unset colorbox
splot "convex1.dat" with lines notitle ,\
"convex1.dat" u 1:2:3 with points palette pointsize 3 pointtype 7
where convex1.dat contains these points
0 0 0
0 0 0.285957
0 0.285957 0.285957
0 0.3812378724 0.1906189362
0 0.571914 0
0.1906761276 0.3812378724 0.1906189362
0.285957 0.285957 0.285957
0.571914 0 0
0.571914 0 0.285957
The representation of this script is:
I can make the convex hull with these points with the Mathematica environment and create the type of figure I am looking for:
The question is: how can I make a convex hull, like the Mathematica figure, with Gnuplot, and how could I use transparency to make figures with comparing two convex hulls with the same axis?
Gnuplot is primarily a renderer for structured numerical data; it's not much of a mathematical processing system, or a renderer for geometry data. There's the pm3d style for splot which allows you to plot arbitrary polygon collections, but it doesn't do hidden surface removal, let alone complex renderings based on the intersection of multiple polygons. In fact, the documentation itself says:
Gnuplot is not [a] virtual reality tool to calculate intersections of filled
polygon meshes.
For this sort of thing, you'll want to use an actual mathematical processing package (like Mathematica!) which can output to a vector format, and then use that directly rather than going through Gnuplot.

Getting smooth curve with gnuplot

I'm not getting smooth curve on gnuplot.
This is my code:
set style line 3 lc rgb '#09ad00' lt 1 lw 1.5 #green
set style line 1 lc rgb '#0060ad' lt 1 lw 2 #blue
set style line 2 lc rgb '#dd181f' lt 1 lw 2 #red
plot [-1:1] f1(x) with line ls 3,f2(x) with line ls 1,f1(x)+f2(x) with line ls 2
I'm getting this plot
while I'm expecting this type of curve
You haven't shown what your particular functions are, but this is almost certainly a sampling problem. Gnuplot doesn't really draw curves for functions - it actually computes the functions at multiple points and connects them with straight lines, similarly to what would happen if you were plotting a data file. The number of points that it computes is user settable.
Suppose that I do plot sin(x) and see this:
Here the sampling rate is set pretty low. We can look at the individual points in order to see what is going on.
In order to improve this, I need to increase the sampling rate by using the set samples ? command. The default is 100 (in 5.0 patch level 6). Depending on how rapidly the function changes, higher values may be needed. I usually set it to around 1000 with set samples 1000. This changes the graph to
which produces a much nicer smooth curve. Again, this is just a bunch of points connected by straight lines, but when there are a lot of these, it looks like a smooth continuous curve.
We can look at the individual points again (using a sampling rate of 100 as 1000 is too many to clearly see the points)
We can also see here that there is not much difference between the graph with 1000 points and 100 points. In the case of a sine curve, 100 is enough to see a smooth graph, but with a faster changing curve, we may need more.
The set samples command takes (optionally) two values, but the second value is only used for 3d plots. You can find out more with the help samples command.

Gnuplot's Graphic Jump

is there a way to avoid the drawing of the near asymptote line in the function 1/(2-x), for example, without usage of conditional plotting? The idea is to draw iterated functions based in this one and, since asymptote changes, using conditional plotting isn't a good solution.
You can plot with points at a very high sampling rate:
set yrange [-10:10]
set samples 100000
plot 1/(2-x) with points
If the singularity occurs at different values of x you can use conditional plotting on y:
f(x)=1/(2-x)
set samples 1000
plot (abs(f(x)) < 10 ? f(x) : 1/0) with lines

for loop with parametric plots in gnuplot

I am trying to plot multiple parametric curves in gnuplot 4.6.
In an earlier version (4.4?), the commands
set para
plot [-pi:pi] for [a=1:10] a*cos(t),a*sin(t)
would result in ten circles centered at the origin with radius 1, 2, ..., 10. In 4.6, the result is one circle of radius 1.
In 4.6, the commands
unset para
plot [-pi:pi] for [a=1:10] a*sin(x)
yield ten beautiful sine curves.
So, it appears that the "for" command now has a problem with parametric curve plotting, I guess.
Does anyone know of a workaround? The circle object is not useful for me: I am interested in general curves. Thanks!
The syntax ambiguity between parametric mode and iteration is a documented bug/limitation in current gnuplot versions. In the development version (4.7) a separate parametric mode is not necessary, as the required sampling variable can be explicitly described in a generic plot command:
plot for [a=1:10] [t=-10:10] '+' using (a*sin(t)):(a*cos(t))
Unfortunately that fully general syntax is not available in version 4.6. The closest I can think of is a simpler variant:
unset parametric
plot for [a=1:10] '+' using (a*sin($1)):(a*cos($1))
This works for your example case, but may not suffice for your actual use case because it conflates the sampling range on the parametric variable with the implicit plotting range on x.

Resources