TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
@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
up vote 12 down vote accepted

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:




\def\LEN{(sqrt((\U)^2 + (\V)^2)}
\begin{axis}[axis equal]
        point meta={\LEN},
            scale arrows=2,
            every arrow/.append style={line width=\pgfplotspointmetatransformed/1000 * 2pt},
    ] {x^2};


enter image description here

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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