我正在尝试合并优秀的解决方案在 pgfplots 极坐标图中使用对数 Y 轴提供出色的解决方案为 pgfplots 极坐标图添加颜色和箭头装饰。每个解决方案单独使用时效果都很好(参见这些链接中的图片)。
不幸的是,将它们组合成一个工作示例的尝试失败了:
\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[>=stealth,
ymin=0, ymax=32,
%ytick=\empty, axis y line=none,
point meta ={rawy},
y coord trafo/.code =\pgfmathparse{log10(#1)},
y coord inv trafo/.code=\pgfmathparse{10^#1},
xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
every axis plot/.append style={ultra thick},
visualization depends on={x\as\myx},
visualization depends on={y\as\myy},
scatter/@pre marker code/.append code={
\pgftransformreset
\pgfmathsetmacro{\mycolor}{(abs(sin(\myx))<0.01 ? "green" :
(abs(cos(\myx))<0.01 ? "red" : "blue"))}
%\typeout{\myx,\myy,\mycolor}
\draw[->,color=\mycolor] (axis cs:0,0) --
(axis cs:\myx,\myy) node[anchor=\myx-180]{\pgfmathprintnumber{\myy}\%};
},
]
\addplot+ [scatter,draw=none]
coordinates {(0,21.6) (180,15.8)
(90,11.4) (270,10.6)
(30,5.3) (60,5.5) (120,4.0) (150,6.6) (210,5.2) (240,5.5) (300,3.4) (330,5.2)};
\end{polaraxis}
\end{tikzpicture}
\end{document}
我错过了什么?
答案1
你应该需要改成ymin=0
例如ymin=1
并破解其中一个。我破解了我更熟悉的那个。
\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[>=stealth,
ymin=1, ymax=36,%<- ymin=1 !
%ytick=\empty, axis y line=none,
point meta ={rawy},
y coord trafo/.code =\pgfmathparse{log10(#1)},
y coord inv trafo/.code=\pgfmathparse{10^#1},
xticklabel=$\pgfmathprintnumber{\tick}^\circ$,
every axis plot/.append style={ultra thick},
visualization depends on={x\as\myx},
visualization depends on={y\as\myy},
scatter/@pre marker code/.append code={
\pgftransformreset
\pgfmathsetmacro{\mycolor}{(abs(sin(\myx))<0.01 ? "green" :
(abs(cos(\myx))<0.01 ? "red" : "blue"))}
\pgfmathsetmacro{\myanchoradd}{(abs(sin(\myx))<0.01 ?-90:0)}
\pgfmathsetmacro{\myundoney}{pow(10,\myy)}
%\typeout{\myx,\myy,\mycolor}
\draw[->,color=\mycolor] (axis cs:0,1) --
(axis cs:\myx,\myundoney)
node[anchor=\myx-180+\myanchoradd]{\pgfmathprintnumber{\myundoney}\%};
},
]
\addplot+ [scatter,draw=none]
coordinates {(0,21.6) (180,15.8)
(90,11.4) (270,10.6)
(30,5.3) (60,5.5) (120,4.0) (150,6.6) (210,5.2) (240,5.5) (300,3.4) (330,5.2)};
\end{polaraxis}
\end{tikzpicture}
\end{document}