我一直在寻找一种移动图表上刻度的方法。我找到了很多有关刻度位置、标签或大小的选项,但我找不到将它们垂直移动到它们所在的轴的方法。
我想匹配 APA 样式的图表:沿 x 轴向上移动所有标签并沿 y 轴向左移动所有标签,以便它们只出现在轴的一侧。
目前,轴将刻度切成两个相等的部分,如下所示。
您知道如何移动这些刻度吗?
\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}
答案1
您可以使用xtick align=inside
和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}