# Reverse xaxis on polar plot

I'm tring to obtain a clockwise polar plot, keeping the zero in north direction. The plot is correctly displayed but I can't fix the xtick style.

\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]
0 1
30 2
60 4
90 6
120 4
};
\end{polaraxis}
\end{tikzpicture}
\end{document}


Here's my output: in the red box you can see the strange xticks rotation.

• Pardon my ignorance, but what exactly are you trying to fix about the xtick style? – John Wickerson Jun 7 '13 at 15:19
• Sorry if my question is unclear. The ticks in the x axis (degree) are strangely rotated due to the x axis reversion and the plot rotation. I'll upload a better image for clarify the question. – bersanri Jun 7 '13 at 15:24
• Yes I see they look funny. Do you want them all perpendicular to the axes? All pointing clockwise or all pointing anticlockwise? – John Wickerson Jun 7 '13 at 15:29
• All perpendicular to the axes will be great. I don't know how to modify this behaviour. – bersanri Jun 7 '13 at 15:38

I believe there's a bug in the polar library: During the calculation of the normal vectors, there should be a check whether the x axis is reversed.

\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}%
{\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
]