2

So, after the brilliant solution of @Symbol1 to my last question, I have a new one on the same topic. With the proposed code, which changes the behavior of \pgfplotsplothandlerquiver@vis@path, point meta seems not to work anymore...

This has effects on the mapped color and \pgfplotspointmetatransformed

\documentclass[border=9,tikz]{standalone} 
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\begin{document}

\makeatletter
\def\pgfplotsplothandlerquiver@vis@path#1{%
    % remember (x,y) in a robust way
    #1%
    \pgfmathsetmacro\pgfplots@quiver@x{\pgf@x}%
    \pgfmathsetmacro\pgfplots@quiver@y{\pgf@y}%
    % calculate (u,v) in relative coordinate
    \pgfplotsaxisvisphasetransformcoordinate\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w%
    \pgfplotsqpointxy{\pgfplots@quiver@u}{\pgfplots@quiver@v}%
    \pgfmathsetmacro\pgfplots@quiver@u{\pgf@x-\pgfplots@quiver@x}%
    \pgfmathsetmacro\pgfplots@quiver@v{\pgf@y-\pgfplots@quiver@y}%
    % move to (x,y) and start drawing
    {%
        \pgftransformshift{\pgfpoint{\pgfplots@quiver@x}{\pgfplots@quiver@y}}%
        \pgfpathmoveto{\pgfpointorigin}%
        \pgfpathlineto{\pgfpoint\pgfplots@quiver@u\pgfplots@quiver@v}%
    }%
}%

  \begin{tikzpicture}
    \begin{axis}[axis equal]

      \addplot[
               point meta=x,
               quiver={u=x,v=y,
                 after arrow/.code={
                   \relax{% always protect the shift
                     \pgftransformshift{\pgfpoint{\pgfplots@quiver@x}{\pgfplots@quiver@y}}%
                     \node[below right]{\tiny\color{mapped color}\pgfplotspointmetatransformed};
                   }
                 }
               },
               ->,
               samples=10,domain=-1:1
              ] {x*x-1};


      \addplot[
               point meta=x,
               quiver={u=x,v=y,
                      every arrow/.append style={%
                        -{Latex[scale length={max(0.1,\pgfplotspointmetatransformed/1000)}]},mapped color
                      },
               },
               ->,
               samples=10,domain=-1:1
              ] {x*x};
   \end{axis}
  \end{tikzpicture}
\end{document}

For the unchanged version, scaling and coloring works, for the changed one neither of the two things work.

enter image description here

For the sake of completion, the original pgfplots code which is replaced (I can't see anything about meta values in here?!?)

\def\pgfplotsplothandlerquiver@vis@path#1{%
    \pgfpathmoveto{#1}%
    \pgfplotsaxisvisphasetransformcoordinate\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w
    \pgfpathlineto{%
        \pgfplotsifcurplotthreedim{%
            \pgfplotsqpointxyz\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w
        }{%
            \pgfplotsqpointxy\pgfplots@quiver@u\pgfplots@quiver@v
        }%
    }%
}%
crateane
  • 2,217

1 Answers1

2

The following works for me.

\documentclass[border=9,tikz]{standalone} 
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\begin{document}

\makeatletter \def\pgfplotsplothandlerquiver@vis@path#1{% % remember (x,y) in a robust way #1% \pgfmathsetmacro\pgfplots@quiver@x{\pgf@x}\global\let\pgfplots@quiver@x\pgfplots@quiver@x% \pgfmathsetmacro\pgfplots@quiver@y{\pgf@y}\global\let\pgfplots@quiver@y\pgfplots@quiver@y% % calculate (u,v) in relative coordinate \pgfplotsaxisvisphasetransformcoordinate\pgfplots@quiver@u\pgfplots@quiver@v\pgfplots@quiver@w% \pgfplotsqpointxy{\pgfplots@quiver@u}{\pgfplots@quiver@v}% \pgfmathsetmacro\pgfplots@quiver@u{\pgf@x-\pgfplots@quiver@x}% \pgfmathsetmacro\pgfplots@quiver@v{\pgf@y-\pgfplots@quiver@y}% % move to (x,y) and start drawing {% \pgftransformshift{\pgfpoint{\pgfplots@quiver@x}{\pgfplots@quiver@y}}% \pgfpathmoveto{\pgfpointorigin}% \pgfpathlineto{\pgfpoint\pgfplots@quiver@u\pgfplots@quiver@v}% }% }%

\begin{tikzpicture}
    \begin{axis}[axis equal]
        \addplot[
            point meta=x,
            quiver={
                u=x,v=y,
                every arrow/.append style={%
                    -{Latex[scale length={max(0.1,\pgfplotspointmetatransformed/1000)}]},mapped color
                },
                after arrow/.code={
                    \relax{% always protect the shift
                        \pgftransformshift{\pgfpoint{\pgfplots@quiver@x}{\pgfplots@quiver@y}}%
                        \node[below right]{\tiny\color{mapped color}\pgfplotspointmetatransformed};
                    }
                }
            },
            ->,samples=10,domain=-1:1
        ]{x*x-1};
        \addplot[
            point meta=x,
            quiver={
                u=x,v=y,
                every arrow/.append style={%
                    -{Latex[scale length={max(0.1,\pgfplotspointmetatransformed/1000)}]},mapped color
                },
            },
            ->,samples=10,domain=-1:1
        ]{x*x};
    \end{axis}
\end{tikzpicture}

\end{document}

Explanation

The main difference of this code and the one in you previous question is that

\pgfmathsetmacro\pgfplots@quiver@x{\pgf@x}
\pgfmathsetmacro\pgfplots@quiver@y{\pgf@y}

is made into

\pgfmathsetmacro\pgfplots@quiver@x{\pgf@x}\global\let\pgfplots@quiver@x\pgfplots@quiver@x%
\pgfmathsetmacro\pgfplots@quiver@y{\pgf@y}\global\let\pgfplots@quiver@y\pgfplots@quiver@y%

which suggests that the error is introduced by extra grouping. But why is there extra grouping? Well, because when pgfplots encounters

\draw[/pgfplots/quiver/every arrow]...

the options of the \draw is, by convention, affecting only this \draw. Hence TikZ will put this \draw in a group. And since \pgfplotsplothandlerquiver@vis@path is thereby put in a group, you cannot see \pgfplots@quiver@x from outside (in particular in after arrow).


By the way, the #1 of the \pgfplotsplothandlerquiver@vis@path is, roughly speaking,

\global\pgf@x=\pgf@x
\global\pgf@x=\pgf@y

And the analysis above shows the necessity of this.

muzimuzhi Z
  • 26,474
Symbol 1
  • 36,855
  • That solved all my issues! See https://tex.stackexchange.com/a/366284/44467 for my final results of the nicer quiver plot. – crateane Apr 23 '17 at 19:24