4

It seems like one of the functions I'm using has a piecewise representation in tikz?

I tried with more sample points, but it did not improve.

I'm getting these jagged edges in my plot. I have no idea why. It should be smooth like this wolframalpha:

smooth

But instead, Its jagged.

But for the values with x greater than 0.5*pi it is smooth. can I set some options in pgf to not approximate the log and trig functions maybe?

jagged

\documentclass[tikz]{standalone}
\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}

  \draw [->,thick] (-1,0) -- (5,0) node[right] {$x$};
  \draw [->,thick] (0,-2) -- (0,2) node[above] {$y$};
  \draw[domain= 0.01*pi:0.99*pi,scale=1.5,samples=600] plot ({deg(\x)}:{-1*ln(tan(\x/2 r))});
  
\end{tikzpicture}

\end{document}
3
  • 1
    Try samples=60
    – user31034
    Commented Jan 11, 2021 at 11:05
  • 1
    Or even samples=30 but adding option smooth
    – NBur
    Commented Jan 11, 2021 at 11:10
  • still doesn't look right with fewer samples.
    – user55924
    Commented Jan 11, 2021 at 11:28

1 Answer 1

9

The default implementation of function ln in tikz (actually pgfmath) is rather basic and not accurate enough. Installing the floating-point calculation only for ln will give smoother calculation results hence fixes the problem.

Quoting Henri Menke's comment:

It should be noted that fpu doesn't actually give you more accuracy (i.e. decimal digits) but significantly increases the range of accessible numbers.

Note the option /pgf/fpu/install only is available since pgf-tikz v3.1.6.

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, fpu}

\begin{document}
\begin{tikzpicture}
  \tikzset{/pgf/fpu/install only=ln}
  \draw [->,thick] (-1,0) -- (5,0) node[right] {$x$};
  \draw [->,thick] (0,-2) -- (0,2) node[above] {$y$};
  \draw[domain= 0.01*pi:0.99*pi,scale=1.5,samples=600] 
    plot ({deg(\x)}:{-1*ln(tan(\x/2 r))});
\end{tikzpicture}
\end{document}

enter image description here

2
  • 2
    It should be noted that fpu doesn't actually give you more accuracy (i.e. decimal digits) but significantly increases the range of accessible numbers. Commented Jan 11, 2021 at 13:07
  • Updating pgf and using fpu was indeed working
    – user55924
    Commented Jan 12, 2021 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .