正确使用 axis cs

正确使用 axis cs

我想复制这个答案给出的结果:pgfplots 中锥体的 HSV 阴影

原始结果

但是当我编译代码时,我得到了这个结果:

我的结果

这是除去不相关部分的代码。我用 标记了相关行%%%%%%


\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
    \begin{tikzpicture}[>=stealth]
\def\arcbegin{0}
\def\arcending{270}

\begin{axis}[
    view={19}{30},
    axis lines=center,
    axis on top,
    domain=0:1,
    y domain=\arcbegin:\arcending,
    xmin=-1.5, xmax=1.5,
    ymin=-1.5, ymax=1.5,
    zmin=0.0, zmax = 1.2,
    hide axis,
    samples = 20,
    data cs=polar,
    mesh/color input=explicit mathparse,
    shader=interp]
% border
\addplot3[
    line width=0.3pt]
    coordinates {(0,0,0) (\arcbegin,1,1) (0,0,1) ({(\arcending)},1,1) (0,0,0) };
%%%%%%% border top
\draw[line width = 0.3pt]
    (axis cs: {cos(\arcbegin)}, {sin(\arcbegin)},1) arc (\arcbegin:\arcending:100);
%%%%%%% arc
\draw[->,line width = 0.6pt]
    (axis cs: {0.5*cos(\arcbegin+20)}, {0.5*sin(\arcbegin+20)},1) arc ({\arcbegin+20}:{\arcending-20}:50);
% x and z axis
\addplot3[
    ,
    line width=0.6pt]
    coordinates {(\arcbegin,1.1,0) (0,0,0) (0,0,1.45)};
% annotations
\node at (axis cs:1.1,0,0) [anchor=north east] {S};
\node at (axis cs:0,0,1.45) [anchor= north east] {V};
\node at (axis cs:-.5,0.0,1.0) [anchor=east] {H};

\end{axis}

\end{tikzpicture}

\end{document}

有谁知道为什么它不再按预期工作了?(注意:箭头末端也丢失了。知道为什么吗?)

答案1

出现了奇怪的输出,因为自从 PGFPlots v1.11全部坐标被解释为axis cs:坐标,坐标也是如此arc

因此,要么写出compat=1.10(或降低),要么分别将s中的100和替换为和。然后您将获得所需的结果(返回)。50arc10.5

\documentclass[border2mm]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % either use a `compat' level below or equal to 1.10, or change
        % `arc' coordinates (as done here)
        compat=1.11,
    }
\begin{document}
    \begin{tikzpicture}[
        >=stealth,
    ]
            \def\arcbegin{0}
            \def\arcending{270}
        \begin{axis}[
            view={19}{30},
            axis lines=center,
            axis on top,
            domain=0:1,
            y domain=\arcbegin:\arcending,
            xmin=-1.5, xmax=1.5,
            ymin=-1.5, ymax=1.5,
            zmin=0.0, zmax=1.2,
            hide axis,
            samples=20,
            data cs=polar,
            mesh/color input=explicit mathparse,
            shader=interp,
        ]
            % -----------------------------------------------------------------
            % also added the "color parts"
            % -----------------------------------------------------------------
            % cone:
            \addplot3 [
                surf,
                variable=\u,
                variable y=\v,
                point meta={symbolic={Hsb=v,u,u}},
            ] (v,u,u);
            % top plane:
            \addplot3 [
                surf,
                samples=50,
                variable=\u,
                variable y=\v,
                point meta={symbolic={Hsb=v,u,1}},
            ] (v,u,1);
            % slice plane
            \addplot3 [
                surf,
                variable=\u,
                y domain=0:1,
                variable y=\w,
                point meta={symbolic={Hsb=\arcbegin,u,z}},
            ] (\arcbegin,u,{u+w*(1-u)});
            \addplot3 [
                surf,
                variable=\u,
                y domain=0:1,
                variable y=\w,
                point meta={symbolic={Hsb=\arcending,u,z}},
            ] (\arcending,u,{u+w*(1-u)});
            % -----------------------------------------------------------------
            % border
            \addplot3 [
                line width=0.3pt,
            ] coordinates {
                (0,0,0) (\arcbegin,1,1) (0,0,1)
                ({(\arcending)},1,1) (0,0,0)
            };
            %%%%%%% border top
            \draw [line width = 0.3pt]
                (axis cs: {cos(\arcbegin)}, {sin(\arcbegin)},1)
%                arc (\arcbegin:\arcending:100)             % <-- old version
                arc (\arcbegin:\arcending:1)                % <-- new version
            ;
            %%%%%%% arc
            \draw [->,line width = 0.6pt]
                (axis cs: {0.5*cos(\arcbegin+20)}, {0.5*sin(\arcbegin+20)},1)
%                arc ({\arcbegin+20}:{\arcending-20}:50)    % <-- old version
                arc ({\arcbegin+20}:{\arcending-20}:0.5)    % <-- new version
            ;
            % x and z axis
            \addplot3[
                line width=0.6pt,
            ] coordinates {
                (\arcbegin,1.1,0)
                (0,0,0)
                (0,0,1.45)
            };
            % annotations
            \node at (axis cs:1.1,0,0)      [anchor=north east] {S};
            \node at (axis cs:0,0,1.45)     [anchor=north east] {V};
            \node at (axis cs:-.5,0.0,1.0)  [anchor=east]       {H};

        \end{axis}
    \end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容