0

I am trying to draw a 3-dimensional half circle arc in PGFPlots using a parametric equation. This is the relevant code.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis lines=middle,
    ticks=none,
    view = {135}{20},
    xlabel=$x$,
    ylabel=$y$,
    zlabel=$z$,
    xmin=-1, xmax=1,
    ymin=-1, ymax=1,
    zmin=0, zmax=1,
    unit vector ratio = 1 1 1,
]
\addplot3[domain=-0.25*pi:0.75*pi,red]
({0.5*cos(deg(x))},{0.5*sin(deg(x))},{0.5});
\end{axis}
\end{tikzpicture}

\end{document}

It doesn't look how I want it to, however. I do not want the ends of the arc to be connected. How do I fix this? Thanks in advance!

enter image description here

2

1 Answer 1

0
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
ticks=none,
view={135}{20},
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
xmin=-1, xmax=1,
ymin=-1, ymax=1,
zmin=0, zmax=1,
%unit vector ratio = 1 1 1,
axis equal,
scale mode=none,
trig format plots=rad,
]
\addplot3[domain=-0.25*pi:0.75*pi, red, samples y=1]({0.5*cos(x)},{0.5*sin(x)},{0.5});
\end{axis}
\end{tikzpicture}
\end{document}

3D graph wit semi circle

From manual p. 125

If you use \addplot3 expression, mesh/rows and mesh/cols are computed from the values samples and samples y. By default, \addplot3 expression always samples a mesh. If you want it to sample a line, set samples y=1 (or, equivalently, y domain=0:0).

1
  • Thank you! samples y=1 did the trick. Thanks also for your other minor improvements of my code. Aug 2 at 17:49

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.