通过点元更改箭筒箭头的颜色

通过点元更改箭筒箭头的颜色

在 PGFPlots 参考第 93 页(版本 1.14)中,有一个示例展示了如何根据点元数据改变箭头线宽。

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
% define some constants:
\def\U{1}
\def\V{2*x}
\def\LEN{(sqrt((\U)^2 + (\V)^2)}
\begin{axis}[axis equal image,
title=Thickness indicates ‘‘strength’’.
]
\addplot[blue,
point meta={\LEN},
quiver={
u={(\U)/\LEN}, v={(\V)/\LEN},
scale arrows=2,
every arrow/.append style={
line width=2pt*\pgfplotspointmetatransformed/1000
},
},
-stealth,samples=15,
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

现在我想通过映射到颜色图来根据点元数据更改箭头颜色而不是线宽\pgfplotspointmetatransformed。我查阅了 pgfplots 参考资料,但没有找到解决方案。

答案1

为此,您只需要color=mapped color在适当的位置添加(查看代码中的注释)。

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    % needed if you only want to color the arrow tips
    % (but I personally use the new/advanced arrows all the times)
    \usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
    % define some constants:
        \def\U{1}
        \def\V{2*x}
        \def\LEN{sqrt((\U)^2 + (\V)^2)}
    \begin{axis}[
        axis equal image,
        title=Thickness indicates ‘‘strength’’.
    ]
        \addplot[
%            % of course you don't need to provide a color here, if you want
%            % to color the whole arrow
%            blue,
            point meta={\LEN},
            quiver={
                u={(\U)/\LEN}, v={(\V)/\LEN},
                scale arrows=2,
                every arrow/.append style={
                    line width=2pt*\pgfplotspointmetatransformed/1000,
                    % ------------------------------------------------
                    % if you want to color the whole arrows, just add
                    color=mapped color,
                    % ------------------------------------------------
                },
            },
            -Stealth,
%            % -------------------------------------------------------
%            % if you want to color the arrow tip only, use this one
%            {-Stealth[mapped color]},
%            % -------------------------------------------------------
            samples=15,
        ] {x^2};
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容