因此,@Symbol1 的绝妙解决方案对于我的上一个问题,我有一个关于同一主题的新问题。使用建议的代码,更改的行为\pgfplotsplothandlerquiver@vis@path
,point meta
似乎不再起作用了……
mapped color
这对和有影响\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}
对于未更改的版本,缩放和着色有效,但对于更改的版本,这两项功能均无效。
为了完整起见,pgfplots
替换了原始代码(我在这里看不到有关元值的任何内容?!?)
\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
}%
}%
}%
答案1
以下对我有用。
\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}
解释
此代码与您上一个问题中的代码的主要区别在于
\pgfmathsetmacro\pgfplots@quiver@x{\pgf@x}
\pgfmathsetmacro\pgfplots@quiver@y{\pgf@y}
制成
\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%
这表明错误是由额外分组引起的。但为什么会有额外的分组?因为当 pgfplots 遇到
\draw[/pgfplots/quiver/every arrow]...
的选项\draw
按照惯例只影响这个\draw
。因此 Ti钾Z 会将其放入\draw
一个组中。由于\pgfplotsplothandlerquiver@vis@path
被放入一个组中,所以您无法\pgfplots@quiver@x
从外部看到(特别是在 中after arrow
)。
顺便说一下,#1
的\pgfplotsplothandlerquiver@vis@path
大致意思是,
\global\pgf@x=\pgf@x
\global\pgf@x=\pgf@y
并且上面的分析也证明了这种做法的必要性。