Take the 2-minute tour ×
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.

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

1 Answer 1

up vote 10 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:

\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]
    \addplot[blue,
        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}

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

 
discard

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.