极坐标图上的反转轴

极坐标图上的反转轴

我试图获得一个顺时针极坐标图,保持零点在北方向。该图显示正确,但我无法修复样式xtick

\documentclass[10pt,border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\usetikzlibrary{shapes.geometric}

\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
    xticklabel style={
        inner xsep= 1pt,
        circle,
        anchor=-\tick+(\pgftransform@angle)
    },
    yticklabel style={
        anchor = 90 + \pgftransform@angle
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[
    x dir = reverse,
    xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
    xtick={0,30,...,330},
    rotate=-90]
\addplot table{
    0 1 
    30 2
    60 4
    90 6
    120 4
    };
\end{polaraxis}
\end{tikzpicture}
\end{document}

这是我的输出:在红色框中您可以看到奇怪的xticks旋转。输出

答案1

我相信该库中有一个错误polar:在计算法线向量时,应该检查 x 轴是否反转。

\documentclass[10pt,border=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\usetikzlibrary{shapes.geometric}

\makeatletter
\def\pgftransform@angle{0}
\pgfplotsset{
    xticklabel style={
        inner xsep= 1pt,
        circle,
        anchor=-\tick+(\pgftransform@angle)
    },
    yticklabel style={
        anchor = 90 + \pgftransform@angle
    }
}

\makeatletter
\def\pgfplotspointonorientedsurfaceabwithbshift@polaraxis#1#2#3{%
    % implement the shift in "b" direction explicitly:
    %
    \pgfplotspointonorientedsurfaceab{#1}{#2}%
    \edef\pgfplots@loc@TMPe{\pgf@x=\the\pgf@x\space\pgf@y=\the\pgf@y\space}%
    \pgfpointadd
        {\pgfplots@loc@TMPe}%
        {%
            \begingroup
            % I need a '-' here because for polaraxis axes, the "b" axis
            % points to the *outside* instead of the inside.
            \pgf@xa=-#3\relax
            \if r\pgfkeysvalueof{/pgfplots/\pgfplotspointonorientedsurfaceB\space dir/value}%
                % oh. a reversed axis.
                \pgf@xa=-\pgf@xa
            \fi
            \edef\pgfmathresult{\pgf@sys@tonumber\pgf@xa}%
            \pgfmath@smuggleone\pgfmathresult
            \endgroup
            \let\pgfplots@loc@TMPa=\pgfmathresult
            \pgfqpointscale{\pgfplots@loc@TMPa}{%
                \if x\pgfplotspointonorientedsurfaceB
                    % the angle.
                    % FIXME : datascaling!
                    % FIXME : aspect ratios!
                    \pgfmath@basic@sin@{#2}%
                    \pgf@x=-\pgfmathresult pt
                    \pgfmath@basic@cos@{#2}%
                    \pgf@y=\pgfmathresult pt
                \else
                    % the length.
                    % FIXME : datascaling!
                    % FIXME : aspect ratios!
                    % perhaps pgfpointpolarxy?
                    \if y\pgfplotspointonorientedsurfaceB
                        \if r\pgfkeysvalueof{/pgfplots/\pgfplotspointonorientedsurfaceA\space dir/value}%
                            \pgfqpointpolar{-#1}{-1pt}%
                        \else
                            \pgfqpointpolar{#1}{1pt}%
                        \fi
                    \else
                        \pgfpointorigin
                    \fi
                \fi
            }%
        }%
}
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[
    x dir =reverse,
    xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
    xtick={0,30,...,330},
    rotate=-90
    ]
\addplot table{
    0 1 
    30 2
    60 4
    90 6
    120 4
    };
\end{polaraxis}
\end{tikzpicture}
\end{document}

相关内容