pgfplot 轴标记

pgfplot 轴标记

这是我第一次尝试使用 pgfplots,有两个问题需要帮助。代码如下:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{verbatim}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=10cm,
height=8cm,
ybar,
ymin=0,
ymax=12000,
ymajorgrids=true,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ylabel={Query Response Time (in ms)},
xlabel={Queries},
symbolic x coords={SA1,SA2,SA3,GA1,GA2,GA3},
%xtick=\empty,
ytick={0,2000,4000,6000,8000,10000},
yticklabels={0,2000,4000,6000,8000,10000},
]
\addplot coordinates {(SA1,192) (SA2,597) (SA3,21) (GA1,750) (GA2,1650) (GA3,489) };
\addplot coordinates {(SA1,300) (SA2,1000) (SA3,226) (GA1,2875) (GA2,8719) (GA3,2235) };
\addplot coordinates {(SA1,375) (SA2,1297) (SA3,360) (GA1,4500) (GA2,10871) (GA3,4580) };
\legend{AQ,CAA,Virtuoso}
\end{axis}
\end{tikzpicture}

\end{document}

这将生成以下图表:

问题 1:如何去除 y 轴顶部的 $*10^4$?

问题 2:如何去掉 x 轴刻度?我尝试输入,xtick=\empty,但出现错误。

在此处输入图片描述

答案1

问题 1:使用scaled y tickskey 并让其pgfplots执行标签(即不指定 key ytickslabel)。

问题 2:使用major x tick style设置transparent使它们不可见。

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    width = 10cm,
    height = 8cm,
    major x tick style = transparent,
    ybar,
    ymin = 0,
    ymax = 12000,
    ymajorgrids = true,
    legend style = {%
      at = {(0.5,-0.2)},
      anchor = north,
      legend columns = -1},
    ylabel = {Query Response Time (in ms)},
    xlabel = {Queries},
    symbolic x coords = {SA1,SA2,SA3,GA1,GA2,GA3},
    ytick = {0,2000,4000,6000,8000,10000},
    scaled y ticks = false,
    ]
    \addplot coordinates {(SA1,192) (SA2,597) (SA3,21) (GA1,750) (GA2,1650) (GA3,489) };
    \addplot coordinates {(SA1,300) (SA2,1000) (SA3,226) (GA1,2875) (GA2,8719) (GA3,2235) };
    \addplot coordinates {(SA1,375) (SA2,1297) (SA3,360) (GA1,4500) (GA2,10871) (GA3,4580) };
    \legend{AQ,CAA,Virtuoso}
  \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容