4

I would like to add the same set of options to every pgfplots “quiver plot”. PGFPlots provides style like every axis plot to add to every plot, but quiver plots are created inside a quiver={...} scope.

The obvious guess was to set a style key called every quiver plot but it doesn't have any effect. Adding quiver keys to every axis plot results in an error.

Here is a minimal non-working example.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotsset{
    every axis/.append style={
        xmin=-1,xmax=1,ymin=-1,ymax=1,
        view={0}{90},
        width=4cm,
        axis equal image
    },
    every axis plot/.append style={
        blue,-stealth,
    },
    % compiles without error but has no effect
    every quiver plot/.style={
        scale arrows=0.5,  
        update limits
    }
}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot3[quiver={u=x,v=y}] {x};
    \end{axis}
\end{tikzpicture}
\qquad
\begin{tikzpicture}
    \begin{axis}
        \addplot3[quiver={u=-y,v=x}] {x};
    \end{axis}
\end{tikzpicture} 
\end{document}

sample code output

5

As soon as I posted it I found a workaround:

\documentclass[png]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotsset{
    every axis/.append style={
        xmin=-1,xmax=1,ymin=-1,ymax=1,
        view={0}{90},
        width=4cm,
        axis equal image
    },
    every axis plot/.append style={
        blue,-stealth,
        quiver={scale arrows=0.5,update limits}
    }
}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot3[quiver={u=x,v=y}] {x};
    \end{axis}
\end{tikzpicture}
\qquad
\begin{tikzpicture}
    \begin{axis}
        \addplot3[quiver={u=-y,v=x}] {x};
    \end{axis}
\end{tikzpicture} 
\end{document}

For some reason I thought that setting quiver keys in the plots would override those set in every axis plot. Luckily, I was mistaken.

sample code output

To achieve the interface I was looking for (i.e., an actual every quiver plot style), you can do it this way:

\pgfplotsset{
    every quiver plot/.style={},
    quiver/.prefix code={\pgfqkeys{/pgfplots/quiver}{/pgfplots/every quiver plot}}
}

Then later:

\pgfplotsset{every quiver plot/.style={
    scale arrows=0.5,  
    update limits
}}
| improve this answer | |

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.