2

In PGFPlots reference page 93 (version 1.14), an example shows how to change the arrow line width according to the point meta.

\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}

Now I want to change the arrow color rather than the line width according to the point meta by mapping \pgfplotspointmetatransformed to colormap. I have look up the pgfplots reference but didn't find a solution.

4

To do that, you only need to add color=mapped color at the appropriate place (have a look at the comments in the code).

% 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}

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.