Try it like this. It seems to work.
Edit. Actually, I made two key changes that restored the centering: I added preview
and removed \centering
. Everything else is irrelevant. Apparently, I should have mentioned this right away.
\documentclass[border=24pt, preview]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{pgfplots.polar}
\begin{document}
\begin{filecontents*}{test_world.dat}
13.4050 52.5200
151.2093 -33.8688
-74.0060 40.7128
\end{filecontents*}
% Berlin
\def\latO{52.5200}
\def\lonO{13.4050}
\pgfmathdeclarefunction{aeqdr}{4}{%
\pgfmathsetmacro\dlon{#1-#3}
\pgfmathsetmacro\argtmp{sin(#4)*sin(#2)+cos(#4)*cos(#2)*cos(\dlon)}
\pgfmathsetmacro\arg{min(1,max(-1,\argtmp))}
\pgfmathsetmacro\cdeg{acos(\arg)}
\pgfmathparse{\cdeg/180}
}
\pgfmathdeclarefunction{aeqdtheta}{4}{%
\pgfmathsetmacro\dlon{#1-#3}
\pgfmathparse{mod(atan2(sin(\dlon)*cos(#2),cos(#4)*sin(#2)-sin(#4)*cos(#2)*cos(\dlon)),360)}
}
%\centering
\begin{tikzpicture}
\begin{polaraxis}[
width=8cm,
height=8cm,
y axis line style={draw=none},
separate axis lines,
ymin=0,
ymax=1,
xtick distance=10,
xticklabel={%
\pgfmathparse{%
int(mod(450-\tick,360))%
}%
\pgfmathprintnumber{%
\pgfmathresult
}\textdegree%
},
yticklabels={},
]
\addplot+[only marks, mark=*, mark size=1.6pt]
table[
x expr = {mod(450 - aeqdtheta(\thisrowno{0},\thisrowno{1},\lonO,\latO), 360)},
y expr = {aeqdr(\thisrowno{0},\thisrowno{1},\lonO,\latO)},
col sep=space,
] {test_world.dat};
\end{polaraxis}
\end{tikzpicture}
\end{document}

Edit 2.
The root of the problem lies in whitespace within pgfmath macros. In pgfmath expressions, every space or line break can affect calculations and positioning. Eliminating these spaces resolves all issues, and the code then behaves correctly.
Edit 3.
Moreover, all spaces between the definitions \def\latO
, \def\lonO
, both \pgfmathdeclarefunction
calls, and before \begin{tikzpicture}
should be removed (I provide the code without these spaces below) — this ensures full symmetry. Even better, move them all to the preamble. And of course, \centering
is unnecessary.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{pgfplots.polar}
\begin{document}
\begin{filecontents*}{test_world.dat}
13.4050 52.5200
151.2093 -33.8688
-74.0060 40.7128
\end{filecontents*}
% Berlin
\def\latO{52.5200}%
\def\lonO{13.4050}%
\pgfmathdeclarefunction{aeqdr}{4}{%
\pgfmathsetmacro\dlon{#1-#3}%
\pgfmathsetmacro\argtmp{sin(#4)*sin(#2)+cos(#4)*cos(#2)*cos(\dlon)}%
\pgfmathsetmacro\arg{min(1,max(-1,\argtmp))}%
\pgfmathsetmacro\cdeg{acos(\arg)}%
\pgfmathparse{\cdeg/180}
}%
\pgfmathdeclarefunction{aeqdtheta}{4}{%
\pgfmathsetmacro\dlon{#1-#3}%
\pgfmathparse{mod(atan2(sin(\dlon)*cos(#2),cos(#4)*sin(#2)-sin(#4)*cos(#2)*cos(\dlon)),360)}
}%
\begin{tikzpicture}
\begin{polaraxis}[
width=8cm,
height=8cm,
y axis line style={draw=none},
separate axis lines,
ymin=0,
ymax=1,
xtick distance=10,
xticklabel={%
\pgfmathparse{%
int(mod(450-\tick,360))%
}%
\pgfmathprintnumber{%
\pgfmathresult
}\textdegree%
},
yticklabels={},
scale only axis, %%%%%%%%%%%%%%%%%%%
]
\addplot+[only marks, mark=*, mark size=1.6pt]
table[
x expr = {mod(450 - aeqdtheta(\thisrowno{0},\thisrowno{1},\lonO,\latO), 360)},
y expr = {aeqdr(\thisrowno{0},\thisrowno{1},\lonO,\latO)},
col sep=space,
] {test_world.dat};
\end{polaraxis}
\end{tikzpicture}
\end{document}
