2

The plotting of the path $x=t,y=\sqrt(1-t^2)$, by using the code

\documentclass[tikz, border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.4}
\begin{document}

\begin{figure}[h]
 \begin{tikzpicture}
        \begin{axis}
        [xlabel=$x$,ylabel=$y$,axis lines=middle, xtick={2},ytick={2},no marks,axis equal,xmin=-1.4,xmax=1.2,ymax=1.2,ymin=-0.2,enlargelimits={upper=0.1}]
             \addplot[no markers,samples=200, domain=-1:1,variable=t]({t},{pow(1-t^2,1/2)});
        \end{axis}
             \draw (5.8,1.2) node {$1$};
             \draw (3.1,1.2) node {$O$};
             \draw (0.93,1.2) node {$-1$};
 \end{tikzpicture}
\end{figure}

\end{document} 

is: enter image description here

But, in a neighborhood of 1 it seems the graph is not complete. And I don't understand why ?enter image description here

Later edit: It seems that the circle is no tsmooth aroun 1 and -1, and I don't know where do I wrong ? enter image description here

1
  • Off-topic: A figure environment is pointless with the standalone class. Remove it.
    – Johannes_B
    Dec 10 '17 at 11:38
1

The issue is that when it divides the interval, it doesn't divide the points appropriately. Instead of writing an even number of samples, write an odd number of samples to fix it.

Instead of samples = 200, write samples = 201.

\begin{document}

\begin{figure}[h]
 \begin{tikzpicture}
        \begin{axis}
        [xlabel=$x$,ylabel=$y$,axis lines=middle, xtick={2},ytick={2},no marks,axis equal,xmin=-1.4,xmax=1.2,ymax=1.2,ymin=-0.2,enlargelimits={upper=0.1}]
             \addplot[no markers,samples=201, domain=-1:1,variable=t]({t},{pow(1-t^2,1/2)});
        \end{axis}
             \draw (5.8,1.2) node {$1$};
             \draw (3.1,1.2) node {$O$};
             \draw (0.93,1.2) node {$-1$};
 \end{tikzpicture}
\end{figure}

\end{document} 

With an odd number of samples

5
  • Thank you very much ! I didn't know that.
    – Cris
    Dec 10 '17 at 11:47
  • No problem. It took me some time to figure that out when I was learning TikZ. If you accept the answer, don't forget to click the tick mark ;) Dec 10 '17 at 11:50
  • But something is weird. It seems that the line circle is not smooth around 1 (see the image in my later edit). Why ?
    – Cris
    Dec 10 '17 at 11:52
  • I mean, you are drawing a square root. Given the inherent imprecision of TikZ. And how a square root behaves, you will have a lot of points around the top part, but not a lot of points around the pole at 1 and -1. Try switching to ({sin(t)},{cos(t)}) with domain=-90:90 to get a "smooth everywhere" plot Dec 10 '17 at 11:58
  • 1
    Ok, thank you ! It's working very well now.
    – Cris
    Dec 10 '17 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.