pgfplots 中的对数 Y 轴 - 数字不准确

pgfplots 中的对数 Y 轴 - 数字不准确

下列的此主题此主题关于 pgfplots 极坐标图中的对数 Y 轴,虽然该解决方案在图形上效果很好,但数字在计算过程中会出现舍入误差。有什么解决方法吗?

在此处输入图片描述

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[>=stealth,
        ymin=1, ymax=20000, ytick=\empty,
        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)}
        \draw[->,color=\mycolor] (axis cs:0,1) -- 
        (axis cs:\myx,\myundoney) 
        node[anchor=\myx-180+\myanchoradd]{\pgfmathprintnumber{\myundoney}};
        },
    ]
    \addplot+ [scatter,draw=none]
    coordinates {
        (0,200.7)   (30,557.4)  (60,270.9)
        (90,82)     (120,399.7) (150,434.9)
        (180,345.7) (210,536.2) (240,256.3)
        (270,108.8) (300,365.1) (330,386.8)};
    \end{polaraxis}
\end{tikzpicture}
\end{document}

答案1

正如薛定谔的猫所提出的,这是我之前删除的提议。

\documentclass[]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{polar}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[>=stealth,
        ymin=1, ymax=9500,
        %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)}
        \typeout{\myx,\myy,\mycolor}
        \draw[->,color=\mycolor] (axis cs:0,1) -- (axis cs:\myx,{10^\myy}) node[anchor=\myx-180+\myanchoradd]{\pgfmathprintnumber\pgfplotspointmeta\%};
        },
    ]
    \addplot+ [scatter,draw=none]
    coordinates {
        (0,200.7)   (30,557.4)  (60,270.9)
        (90,82)     (120,399.7) (150,434.9)
        (180,345.7) (210,536.2) (240,256.3)
        (270,108.8) (300,365.1) (330,386.8)};
    \end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容