X 轴隐藏在栅栏后面

X 轴隐藏在栅栏后面

在下面的条形图中,x 轴隐藏在条形后面。我需要将条形置于 x 轴后面来查看。

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations}
\usepackage{float}
\usepackage{pgfkeys}
\usepackage{pgfmath} 
\pgfplotsset{plot coordinates/math parser=false}
\begin{document} 
\begin{tikzpicture}{scale=0.3}
\begin{axis}[width=12cm,height=8cm,
    ybar,
    tick label style={font=\small},
    tickpos=left,
    xticklabels={A1, B2 ,C3, D4, E5,F6, G7, H8, I9}, 
    xtick={1,2,3,4,5,6,7,8,9},
    ymin=0,
    legend entries={entry1,entry2},
    y tick label style={/pgf/number format/.cd,%
          scaled y ticks = false,
          set thousands separator={},
          fixed
    },     /pgf/number format/fixed, 
/pgf/number format/precision=2,
xticklabel style={name=T\ticknum}% names every xtick label node T0,T1, ...
]
    ]
    \addplot +[bar shift=-.182cm, area legend,blue!30,] coordinates {(1,350) (2,325) (3,300) (4,275)     (5,250) (6,240) (7,230) (8,220)(9,210)};

    \addplot  +[bar shift=.182cm, area legend,red!30]coordinates {(1,550) (2,750) (3,380) (4,320) (5,280)(6,270)(7,260)(8,250)(9,240)};
\end{axis}
\begin{scope}[decoration=brace]
    \pgfdecorationsegmentamplitude=5pt
    \draw[decorate] (T8.south east) -- (T0.south west) node[midway,below=\pgfdecorationsegmentamplitude] {Months};
\end{scope}
\end{tikzpicture}
\end{document}

我希望它看起来像这样。

在此处输入图片描述

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} %added
\begin{document} 
\begin{tikzpicture}
\begin{axis}[
width=12cm,
ybar,
tick label style={font=\small},
tickpos=left,
xtick={1,2,3,4,5,6,7,8,9},
xticklabels={A1, B2 ,C3, D4, E5,F6, G7, H8, I9}, 
ymin=0,
legend entries={entry1,entry2},
axis on top, %added
]
\addplot+[bar shift=-.182cm, area legend, blue!30,] coordinates {(1,350) (2,325) (3,300) (4,275)     (5,250) (6,240) (7,230) (8,220)(9,210)};
\addplot+[bar shift=.182cm, area legend, red!30] coordinates {(1,550) (2,750) (3,380) (4,320) (5,280)(6,270)(7,260)(8,250)(9,240)};
\end{axis}
\end{tikzpicture}
\end{document}

条状图

相关内容