带有 pgfplots polar 坐标的节点

带有 pgfplots polar 坐标的节点

使用 pgfplots 绘制极坐标图,是否可以在每条数据线的边缘写入 y 值,这样该线就不会隐藏该值(如图所示)?

在此处输入图片描述

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

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        ymin=0, ymax=25, ytick=\empty,
        nodes near coords,
        every axis plot/.append style={ultra thick}
    ]
    \addplot+ [polar comb]
    coordinates {
        (0,21.6)(30,5.3)(60,5.5)(90,11.4)
        (120,4.0)(150,6.6)(180,15.8)(210,5.2)
        (240,5.5)(270,10.6)(300,3.4)(330,5.2)
    };
    \end{polaraxis}
\end{tikzpicture}
\end{document}

答案1

欢迎!是的,你可以让节点的锚点取决于角度,即坐标x。一个选项是

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

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        ymin=0, ymax=30, ytick=\empty,
        nodes near coords,
        every axis plot/.append style={ultra thick},
        visualization depends on={x\as\myx},
        nodes near coords style={anchor=\myx-180}
    ]
    \addplot+ [polar comb]
    coordinates {
        (0,21.6)(30,5.3)(60,5.5)(90,11.4)
        (120,4.0)(150,6.6)(180,15.8)(210,5.2)
        (240,5.5)(270,10.6)(300,3.4)(330,5.2)
    };
    \end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

您还可以添加对的依赖\coordindex

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

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        ymin=0, ymax=25, ytick=\empty,
        nodes near coords,
        every axis plot/.append style={ultra thick},
        visualization depends on={x+(\coordindex==0?90:0)\as\myx},
        nodes near coords style={anchor=\myx-180}
    ]
    \addplot+ [polar comb]
    coordinates {
        (0,21.6)(30,5.3)(60,5.5)(90,11.4)
        (120,4.0)(150,6.6)(180,15.8)(210,5.2)
        (240,5.5)(270,10.6)(300,3.4)(330,5.2)
    };
    \end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

或者使其x依赖y

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

\begin{document}
\begin{tikzpicture}
    \begin{polaraxis}[
        ymin=0, ymax=25, ytick=\empty,
        nodes near coords,
        every axis plot/.append style={ultra thick},
        visualization depends on={(y>15?-90:x-180)\as\myanchor},
        nodes near coords style={anchor=\myanchor}
    ]
    \addplot+ [polar comb]
    coordinates {
        (0,21.6)(30,5.3)(60,5.5)(90,11.4)
        (120,4.0)(150,6.6)(180,15.8)(210,5.2)
        (240,5.5)(270,10.6)(300,3.4)(330,5.2)
    };
    \end{polaraxis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容