使图表网格更加细粒度

使图表网格更加细粒度

对于下面的 MWE:

\documentclass{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{tikz,pgf}


\usepackage{pgfplots}
\usepackage{slashbox}
\usepackage{bchart}


\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols,automata}

\begin{document}

\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[%
scaled y ticks = true,
width=1*\textwidth,
height=8cm,
xlabel={Query},
ylabel={Elapsed Time (in seconds)},
xmajorgrids,
ymajorgrids,
zmajorgrids,
enlarge x limits=0,
scaled x ticks = true]
\addplot [
color=red,
solid,
line width=1.0pt
]
coordinates{
(0,10)
(1,4)
(2,5)
};
\end{axis}
\end{tikzpicture}
\caption{Blah}
\end{figure}

\end{document}

我怎样才能使网格更加细粒度?

答案1

您不需要为每个轴网格定义样式。grid=major一次性设置所有样式。此外,您还需要引入次要刻度以获得更精细的网格,然后您可以使用grid=both这意味着minor和。如果以下内容还不够,您可以对轴或选项major执行相同操作。yminor tick

\documentclass{report}
\usepackage[left=2.5cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
%\usepackage{tikz,pgf} %Pgfplots loads TikZ, and TikZ loads PGF by default



\usepackage{pgfplots}
%================================  You don't need all this for the MWE
\usepackage{slashbox}
\usepackage{bchart}


\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols,automata}
%%=================================
\begin{document}

\begin{figure}[H]
\begin{tikzpicture}
\begin{axis}[%
scaled y ticks = true,
width=\textwidth,
height=8cm,
xlabel={Query},
ylabel={Elapsed Time (in seconds)},
grid=both,
ticks=both,
minor xtick={0,0.1,...,2},
enlarge x limits=0,
scaled x ticks = true
]
\addplot [
color=red,
solid,
line width=1.0pt
]
coordinates{
(0,10)
(1,4)
(2,5)
};
\end{axis}
\end{tikzpicture}
\caption{Blah}
\end{figure}

\end{document}

在此处输入图片描述

相关内容