7

For the MWE below:

\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}

How can I make the grids finer grained ?

8

You don't need to define the style for each axis grid. grid=major sets all of them at once. Also you need to introduce minor ticks to get finer grid then you can use grid=both which means minor and major. If the following is not enough you can do the same for the y axis or minor tick option.

\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}

enter image description here

  • 3
    Instead of saying minor x tick={0,0.1,...,2}, you can also say minor x tick num=1, which will put one minor tick between each pair of major ticks. This has the advantage of not drawing the grid lines at the major tick positions twice, and you don't need to worry about adjusting the minor tick range if you change the axis range. – Jake Aug 30 '12 at 6:35
  • @Cemre Jake is right! I keep on forgetting that option. – percusse Aug 30 '12 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.