首先,我希望pgfplots
图表(和小网格)中每个主要刻度之间都有一个小刻度。我写了minor tick num=1
但不起作用。我没有使用对数轴,所以这与其他问题无关。
其次,为什么每个轴上都缺少刻度标签“1”?如何显示该标签?
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
footnotesize,
width=4in,
height=4in,
axis equal,
scale only axis,
separate axis lines,
grid=both,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1,
xlabel={X},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=0,
ymax=1,
ylabel={Y},
minor tick num=1,
xtick={0,0.1,...,1},
ytick={0,0.1,...,1},
axis background/.style={fill=white},
legend style={at={(0.97,0.03)},anchor=south east,legend cell align=left,align=left,fill=white}
]
\end{axis}
\end{tikzpicture}%
\end{document}
答案1
明确设置所有刻度有效:
\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
grid=both,
minor tick num=1,
xtick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ytick={0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
]
\end{axis}
\end{tikzpicture}%
\end{document}
我认为这是由舍入误差引起的。您可以很容易地看到,0,0.1,...,1
如果数字与上面的数字相同,则不会创建相同的序列
\documentclass{article}
\usepackage{pgffor}
\begin{document}
\foreach \x in {0,0.1,...,1} {
\x
}
\end{document}
输出
两个轴上都缺少刻度的原因1
很清楚。我不确定为什么缺少小刻度,可能是因为主刻度之间的距离不都相等,至少手册上是这么写的
如果主刻度不具有相同的距离,则次刻度将被禁用,并且它们当前仅适用于线性轴(不适用于对数轴)。
答案2
你也可以尝试
xtick distance=.1,
ytick distance=.1,
代替xtick={0,0.1,...,1},ytick={0,0.1,...,1},
。
代码:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
footnotesize,
width=4in,
height=4in,
axis equal,
scale only axis,
separate axis lines,
grid=both,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}},
xmin=0,
xmax=1,
xlabel={X},
every outer y axis line/.append style={black},
every y tick label/.append style={font=\color{black}},
ymin=0,
ymax=1,
ylabel={Y},
minor tick num=1,
xtick distance=.1,% <-
ytick distance=.1,% <-
axis background/.style={fill=white},
legend style={at={(0.97,0.03)},anchor=south east,legend cell align=left,align=left,fill=white}
]
\end{axis}
\end{tikzpicture}%
\end{document}