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.

The pgfplots manual says that axis on top=true won't affect the plot if using plotmarks as this usually doesn't make sense, which I agree with. However, in this case I'd prefer both the axis and tick labels to be on top of the plot marks; is there any way to force this, or any workaround available?

At the moment, my output becomes as in the attached figure,

enter image description here

using the following options

\begin{axis}[%
axis on top=true,
view={0}{90},
axis y line = center,
axis x line = center,
xmin=-2,xmax=2,
ymin=-2,ymax=2,
xtick={-2,-1.5,-1,-0.5,0,0.5,1,1.5,2},
xticklabels={$-2c$,$-1.5c$,$-c$,$-0.5c$,$0$,$0.5c$,$c$,$1.5c$,$2c$},
ytick={-2,-1.5,-1,-0.5,0,0.5,1,1.5,2},
yticklabels={$-2d$,$-1.5d$,$-d$,$-0.5d$,$0$,$0.5d$,$d$,$1.5d$,$2d$},
width=4in,
height=3in,
scale only axis,
xlabel={$\phi_1$},
ylabel={$\phi_2$}]

Code for MWE:

\documentclass[12pt]{standalone}

\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\input{sn2.tikz}

\end{document}

sn2.tikz can be found in the link below

Link to sn2.tikz: sn2.tikz

share|improve this question
1  
Can you please include a compilable example, no matter how small it is? We can't test anything with these options list. –  percusse May 17 '12 at 12:44
    
Sure, here you go: dl.dropbox.com/u/13366636/sn2.tikz . (I've also added the link in the question). –  militiaOfDeath May 17 '12 at 12:45
3  
Thanks, but I think I forgot to say minimal :) Also that's still not compilable I know what to add before and after but I'm requesting it for the house keeping purposes. –  percusse May 17 '12 at 12:53
    
Doh, that's true! Give me some minutes and I'll try to make a minimal tex-file with only the required packages. :) –  militiaOfDeath May 17 '12 at 12:57
    
Added code for MWE + link to a tikz-file with much less data points (400 in total if I'm not wrong). –  militiaOfDeath May 17 '12 at 13:05

2 Answers 2

up vote 5 down vote accepted

Because you are plotting quite a lot of number of points, I would just seperate the plotting part and the cosmetic axis part. I have removed everything related to the plotting axis and defined a new one on top . Also changed the color to yellow to show that the axis is indeed over the markers.

\documentclass[12pt]{standalone}

\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}

%Data plot 
\begin{axis}[xmin=-2,xmax=2,ymin=-2,ymax=2,axis lines = none]
\addplot [color=yellow,only marks,mark=x,mark options={solid}]
    coordinates{(0.52,-0.15) (0.52,-0.16)(0.52,-0.17)(0.52,-0.19)(0.52,-0.2)};
\end{axis}

% Dummy axis
\begin{axis}[%
axis on top=true,
axis y line = center,
axis x line = center,
xmin=-2,xmax=2,
ymin=-2,ymax=2,
xtick={-2,-1.5,-1,-0.5,0,0.5,1,1.5,2},
xticklabels={$-2c$,$-1.5c$,$-c$,$-0.5c$,$0$,$0.5c$,$c$,$1.5c$,$2c$},
ytick={-2,-1.5,-1,-0.5,0,0.5,1,1.5,2},
yticklabels={$-2d$,$-1.5d$,$-d$,$-0.5d$,$0$,$0.5d$,$d$,$1.5d$,$2d$},
xlabel={$\phi_1$},
ylabel={$\phi_2$}]
]
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
    
Thanks a lot! Clever workaround! –  militiaOfDeath May 17 '12 at 13:33

You can use the approach described in tikz/pgfplots advanced z-order axis/grid to define a new style axis line on top. This has the advantage that you don't have to manually keep the options of two axes in sync.

\documentclass[12pt]{standalone}

\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\makeatletter \newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis} \makeatother

\pgfplotsset{axis line on top/.style={
  axis line style=transparent,
  ticklabel style=transparent,
  tick style=transparent,
  axis on top=false,
  after end axis/.append code={
    \pgfplotsset{axis line style=opaque,
      ticklabel style=opaque,
      tick style=opaque,
      grid=none}
    \pgfplotsdrawaxis}
  }
}


\begin{document}

\begin{tikzpicture}

%Data plot 
\begin{axis}[xmin=-2,xmax=2,ymin=-2,ymax=2,axis line on top,
axis y line = center,
axis x line = center,
xmin=-2,xmax=2,
ymin=-2,ymax=2,
xtick={-2,-1.5,-1,-0.5,0,0.5,1,1.5,2},
xticklabels={$-2c$,$-1.5c$,$-c$,$-0.5c$,$0$,$0.5c$,$c$,$1.5c$,$2c$},
ytick={-2,-1.5,-1,-0.5,0,0.5,1,1.5,2},
yticklabels={$-2d$,$-1.5d$,$-d$,$-0.5d$,$0$,$0.5d$,$d$,$1.5d$,$2d$},
xlabel={$\phi_1$},
ylabel={$\phi_2$}]
\addplot [color=yellow,only marks,mark=x,mark options={solid}]
    coordinates{(0.52,-0.15) (0.52,-0.16)(0.52,-0.17)(0.52,-0.19)(0.52,-0.2)};
\end{axis}

% Dummy axis
\begin{axis}[%
]
]
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Thanks, that do seem a bit simpler than the other solution. –  militiaOfDeath May 21 '12 at 6:44

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.