图中刻度线位于实际图后面的一层。请看下面的示例:
\documentclass[11pt, oneside]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0,ymax=1,enlargelimits=false]
\addplot
[const plot,fill=blue,draw=black]
coordinates
{(0,0.1) (0.1,0.15) (0.15,0.02) (0.3,0.62)
(0.4,0.56) (0.5,0.58) (0.6,0.65) (0.7,0.6)
(0.8,0.58) (0.9,0.55) (1,0.52)}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
产生了这个情节:
很明显,绘图已绘制在刻度线上方,0.2 的刻度线清楚地表明了这一点:它大部分被绘图覆盖。如果有人能指导我如何将刻度线放在绘图上方,以便可以看到底部和右侧被覆盖的刻度线,我将不胜感激。
答案1
根据 selwyndd21 的建议,我采用了这个问题现在标记清晰可见:
\documentclass[11pt, oneside]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\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{tikzpicture}
\begin{axis}[ymin=0,ymax=1,enlargelimits=false,axis line on top]
\addplot
[const plot,fill=blue,draw=black]
coordinates
{(0,0.1) (0.1,0.15) (0.15,0.02) (0.3,0.62)
(0.4,0.56) (0.5,0.58) (0.6,0.65) (0.7,0.6)
(0.8,0.58) (0.9,0.55) (1,0.52)}
\closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
结果如下: