Why is gnuplot using a straight-line approximation in this plot

gnuplot

I am plotting a fairly simple function over a specific range. The function is just f(x) = 0.12 * sqrt(x). Here's my gnuplot "code" so far:

set border linewidth 1.5
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2

set xrange [0:12000]
set yrange [0:13]
set xlabel 'Hours' offset 0,0.5
set ylabel 'Level' offset 1,0
set ytics 1
set xtics 2000
set tics scale 0.75
set key bottom right
set grid

f(x) = 0.12 * sqrt(x)

set terminal svg size 1920,1080 font 'Fira Code Nerd Font Mono,20'
set output 'sqrt.svg'
plot f(x) title 'Example Function' with lines linestyle 1

If you take a look at the svg (or even just use the default qt output) the function is a straight line from 0 to about 200 on the x-axis (look in the very bottom-left of the plot), even though this function is not a straight line. This causes some points I am adding to be offset in that area, requiring me to just manually change the data to get them to look right.

Version:

$ gnuplot --version
gnuplot 5.4 patchlevel 3

I have no idea why it's doing this, and especially why it's only doing it for small values of x.

Here's the image I'm getting, just in case someone else can't reproduce it (I've converted the svg to png and added a background layer, but the plot itself isn't different in the svg):

Plot

Best Answer

This is a different application, but the same problem as Weird looking square root on pgfplots.

The sqrt(x) function has a vertical tangent at 0, showing a discontinuity when you sample it with equally spaced x steps. You can have a better approximation (unless you zoom in) by setting, for example, set samples 1000 (default is 100, show samples will tell you).

Unfortunately, in Gnuplot you can't apply smooth to function plotting, for what I know, so that is not a solution. In pgfplots you can get away with spline smoothing, which does almost the right thing.

Or plotting it parametrically so that you have equally spaced y steps, as in, for example

gnuplot> set parametric
gnuplot> set trange[0:sqrt(12000)]
gnuplot> plot t*t, 0.12*t

parametric plot with default samples