# How can I draw a quiver plot with varying line thickness?

This question originates in Scalar field in pgfplots .

How can I draw a quiver plot in which the arrows have the same length, but their line width varies according to some scalar property of the vectors?

-
@marko please note this answer to your feature request in tex.stackexchange.com/questions/51103/scalar-field-in-pgfplots – Christian Feuersänger Apr 10 '12 at 18:11

Pgfplots allows to employ point meta as additional input coordinate. Typically, point meta is used as color data, but it can also be used for different purposes.

In this case, you can use it as line thickness parameter for a quiver plot:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\def\U{1}
\def\V{2*x}
\def\LEN{(sqrt((\U)^2 + (\V)^2)}
\begin{axis}[axis equal]
point meta={\LEN},
quiver={
u={(\U)/\LEN},v={(\V)/\LEN},
scale arrows=2,
every arrow/.append style={line width=\pgfplotspointmetatransformed/1000 * 2pt},
},
-stealth,samples=15,
] {x^2};
\end{axis}
\end{tikzpicture}

\end{document}


The example defines some macros \U, \V, and \LEN where \LEN is the length of these vectors. Then, a quiver plot is drawn where each vector is normalized to unit length - and the length parameter is assigned as point meta. This is a simple and standard way of communicating extra data to plots (you could also input extra values in a table).

Finally, \pgfplotspointmetatransformed is a scalar value in the range [0,1000] such that 0 corresponds to the minimum point meta value and 1000 corresponds to the maximum point meta value.

The expression for the line width scales this linearly such that the minimum line thickness is 0 and the maximum is 2pt.

Note that axis equal is necessary if we want to see that the vectors have the same sizes.

-