[Tex/LaTex] How to plot abs(sin(x)) with gnuplottex

gnuplotgnuplottex

Here is my MWE. Why doesn't it reaches the x-axis?

\documentclass{standalone}
\usepackage[miktex]{gnuplottex}
\begin{document}
    \begin{gnuplot}
        set terminal epslatex color  
        set xzeroaxis lt -1
        set yzeroaxis lt -1
        set grid xtics lc rgb '#555555' lw 1 lt 0
        set grid ytics lc rgb '#555555' lw 1 lt 0
        set yrange [-2:2]
        set xrange [-2*pi:2*pi]
        plot abs(sin(x))
    \end{gnuplot}
\end{document}

Best Answer

What happens is that gnuplot is sampling the x-axis. It means that it does not compute the function for all the possible points in the interval [-2*pi:2*pi] but only a finite number of points. The corresponding y-values are then linked together with a line to complete the plot. If the number of samples is too low you obtain a behaviour similar to yours. The best course of action is then to increase the number of samples considered by adding something like set sample 1000 (tested with gnuplot but not with gnuplottex).

\documentclass{standalone}
\usepackage[miktex]{gnuplottex}
\begin{document}
    \begin{gnuplot}
        set terminal epslatex color  
        set xzeroaxis lt -1
        set yzeroaxis lt -1
        set grid xtics lc rgb '#555555' lw 1 lt 0
        set grid ytics lc rgb '#555555' lw 1 lt 0
        set yrange [-2:2]
        set xrange [-2*pi:2*pi]
        set sample 1000
        plot abs(sin(x))
    \end{gnuplot}
\end{document}

In gnuplot with set sample 100: When sample is set to 100

In gnuplot with set sample 1000: enter image description here