2

my issue is related to the sequence of layers in pgfplots. I have 3 layers:

  1. External graphics, which is included by \addplot graphics
  2. Axis grids and ticks
  3. Additional 'quiver' drawing from \addplot

which I would like to see in (1-2-3) layer sequence (external graphics is the bottom layer).

I could get (2-1-3) if I do nothing special,

(1-3-2) if I use axis on top,

\pgfplotsset{set layers} almost do the job, but axis frame is still under the external graphics,

and finally I found (1-2-3) is possible but in case of using two axis environments.

So, what is the best way to produce desired (1-2-3) layer sequence?

Here is example of the code:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
%\pgfplotsset{set layers}

\begin{axis}[
grid=both,
enlargelimits=false,
axis on top
]

\addplot graphics [xmin=0,xmax=1,ymin=0,ymax=1] {demo};

\addplot [thick,yellow,
quiver={u=\thisrow{u},v=\thisrow{v},update limits=false},-stealth] 
table
{
    x y u v
    0.4 0.5 0 0.1
};

\end{axis}
\end{tikzpicture}

\end{document}
3
  • Tikz layers? You can declare layers background, main, foreground and then place tikzpictures/scopes in each. – Alenanno May 31 '15 at 12:20
  • Can you post your code? That'd be helpful. The graphics is not necessary (we can use an example image). – Alenanno May 31 '15 at 12:25
  • I've added an example of the file, hope it will help – user54824 May 31 '15 at 15:23
1

Library backgrounds helps:

\usetikzlibrary{backgrounds}
...
\addplot[on background layer] graphics ...

Full example (without axis on top and a little more present lines):

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{pgfplots}
\usetikzlibrary{backgrounds}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  grid=both,
  grid style={semithick, white},
  tick style={semithick, white},
  enlargelimits=false,
]

\addplot[on background layer] graphics [xmin=0,xmax=1,ymin=0,ymax=1] {demo};

\addplot [ultra thick, yellow,
  quiver={u=\thisrow{u},v=\thisrow{v},update limits=false},-stealth]
table
{
    x y u v
    0.4 0.5 0 0.1
};
\end{axis}
\end{tikzpicture}
\end{document}

Result

Thus the image is in the background, the axis stuff with grid follows, on top is the "quiver" drawing.

1
  • Perfect, thanks! Also the same result I got recently with: \begin{axis}[set layers,...] and then \addplot[on layer=axis background] graphics{...};, i.e. through the pgfplots features. – user54824 May 31 '15 at 17:06

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.