条形图未显示 Y 轴值

条形图未显示 Y 轴值

问题:Y 轴值未显示在条形图上。

输出:

在此处输入图片描述

乳胶代码:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.18}
\pgfplotstableread[col sep=comma]{
  X,  Y1, Y2
Action selection, 1.7, 2.1
Env.step,  4.7, 6.3
Update all trainers,  3.3, 3.9
Total time, 3.2, 4.5
    }\mydata
    \begin{document}
    \begin{tikzpicture}
    \begin{axis}[
        height=75mm, width=100mm,
%
        bar width=0.22,
        ybar=2pt,
        enlarge x limits={abs=0.5},
        ymin=0,
        ymax=10,
        ytick distance=20,
        yticklabel style={font=\footnotesize},
        xticklabel style={font=\footnotesize},
        %yticklabel=\pgfmathprintnumber{\tick}\,$\%$,
        ylabel={Growth rate (NX)},
        xlabel={Kernel name},
        xtick=data,
        xticklabels from table={\mydata}{X},
%
        nodes near coords,
        nodes near coords style={font=\tiny,
                                 /pgf/number format/.cd,
                                            precision=1,
                                            zerofill,
                                 },
        legend style={legend pos=north east,
                      cells={anchor=west},
                      font=\footnotesize,
                      }
    ]
\addplot [ybar, fill=black] table [x expr=\coordindex,y=Y1]{\mydata};
\addplot [ybar, fill=orange] table [x expr=\coordindex,y=Y2]{\mydata};
\legend{3 to 6 agents, 6 to 12 agents}    \end{axis}
    \end{tikzpicture}
    \end{document}

有人能帮我解决这个问题吗?

答案1

消除ytick distance=20

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{compat=1.18}
\pgfplotstableread[col sep=comma]{
X,  Y1, Y2
Action selection, 1.7, 2.1
Env.step,  4.7, 6.3
Update all trainers,  3.3, 3.9
Total time, 3.2, 4.5
}\mydata
\begin{document}
\begin{tikzpicture}
\begin{axis}[
height=75mm, width=100mm,
bar width=0.22,
ybar=2pt,
enlarge x limits={abs=0.5},
ymin=0,
ymax=10,
%ytick distance=20,
yticklabel style={font=\footnotesize},
xticklabel style={font=\footnotesize},
ylabel={Growth rate (NX)},
xlabel={Kernel name},
xtick=data,
xticklabels from table={\mydata}{X},
nodes near coords,
nodes near coords style={font=\tiny,
/pgf/number format/.cd,
precision=1,
zerofill,
},
legend style={legend pos=north east,
cells={anchor=west},
font=\footnotesize,
}
]
\addplot [ybar, fill=black] table [x expr=\coordindex,y=Y1]{\mydata};
\addplot [ybar, fill=orange] table [x expr=\coordindex,y=Y2]{\mydata};
\legend{3 to 6 agents, 6 to 12 agents}
\end{axis}
\end{tikzpicture}
\end{document}

条状图

相关内容