6

I have been looking for a while for a way to shift ticks on a graph. I found many options regarding ticks positions, labels or size but I could not find a way to move them orthogonally to the axis they are on.

I would like to match APA style graphs: shift up all the labels along the x axis and move left all the labels along the y axis so that they only appear on one side of the axis.

Currently, the axis cut the ticks in two equal parts as shown below.

Would you have any idea on how to move these ticks ?

\documentclass[10pt]{standalone}
\usepackage[T1]{fontenc} 
\usepackage{times} 
\usepackage{tikz} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.6} 
\pgfplotsset{ every non boxed x axis/.append style={x axis line style=-},
 every non boxed y axis/.append style={y axis line style=-}}
\begin{document} 
\footnotesize 
\begin{tikzpicture}
\begin{axis}[%
x tick label style={major tick length=5pt},
width=6cm,
height=6cm,
scale only axis,
xmin=-0.8444, xmax=0.8223,
axis lines=left,
xtick={-0.8444,-0.4277,-0.0110,0.4056,0.8223},
xticklabels={-0.8444,-0.4277,-0.0110,0.4056,0.8223},
ymin=0, ymax=0.3]
\addplot [
color=blue,
solid,
mark=*,
mark options={fill=blue,solid}
]
coordinates{(-0.8444,0.2702)(-0.4277,0.2206)(-0.011,0.171)(0.4056,0.1213)(0.8223,0.0717)};
\end{axis}
\end{tikzpicture} 
\end{document} 
6

You can use xtick align=inside and ytick align=outside:

\documentclass[10pt]{standalone}
\usepackage[T1]{fontenc} 
\usepackage{times} 
\usepackage{tikz} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.6} 
\pgfplotsset{ every non boxed x axis/.append style={x axis line style=-},
 every non boxed y axis/.append style={y axis line style=-}}
\begin{document} 
\footnotesize 
\begin{tikzpicture}
\begin{axis}[%
x tick label style={major tick length=5pt},
width=6cm,
height=6cm,
scale only axis,
xmin=-0.8444, xmax=0.8223,
axis lines=left,
xtick={-0.8444,-0.4277,-0.0110,0.4056,0.8223},
xticklabels={-0.8444,-0.4277,-0.0110,0.4056,0.8223},
xtick align=inside,
ytick align=outside,
ymin=0, ymax=0.3]
\addplot [
color=blue,
solid,
mark=*,
mark options={fill=blue,solid}
]
coordinates{(-0.8444,0.2702)(-0.4277,0.2206)(-0.011,0.171)(0.4056,0.1213)(0.8223,0.0717)};
\end{axis}
\end{tikzpicture} 
\end{document}

enter image description here

| improve this answer | |
  • 1
    Thanks a lot for this reply. However, there is a trick with APA style since the ticks on the y axis should actually be on the left of the axis. Thus I would need some kind of "inside" for the x axis and "outside" for the y axis. That's why I found it so tricky... – Alain May 11 '13 at 1:33
  • 1
    @Alain it's not tricky at all. Please see my updated answer. – Gonzalo Medina May 11 '13 at 1:35

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.