3

I'm not stuck to using pgfplots to produce this, so feel free to offer suggestions.

For my exam papers, I want to provide the students with blank semi-log grids to do hand plots. (To be specific, they are making Bode diagrams).

The following definition approximates the behaviour that I want. The only problem is controlling the divisions along y:

\NewDocumentCommand\BodeGrid{mmmm}{
\pgfplotsset{width=#1, height=#2}
\begin{tikzpicture}
\begin{axis}[
    xmode=log,
    xmin=1e0, xmax=1e#3,
    ymin=0, ymax=#4,
    grid=both,
    major grid style={black!50},
    yticklabels={},
    xticklabels={},
]
\end{axis}
\end{tikzpicture}
}

The arguments here are the width and height, then I want to specify the number of decades along x, then the number of divisions along y. The x-axis works just fine because it will automatically produce the appropriate number of decades according to the range, if I provide an integer. The y axis, however, is at the mercy of the code which automatically divides the axis. For some range of integers (for y, the 4th argument), this command actually does what I want.

For example, \BodeGrid{\textwidth}{0.75\textheight}{3}{12} produces:

enter image description here

5

Your plot is empty of actual points so pgfplots is smart enough to not to bother. If you pretend that you are actually drawing something it will cooperate.

\documentclass{standalone}
\usepackage{pgfplots}
\newcommand{\BodeGrid}[4]{\begin{tikzpicture}
\begin{axis}[width=#1, height=#2,
    xmode=log,
    xmin=1e0, xmax=1e#3,
    ymin=0, ymax=#4,
    grid=both,
    major grid style={black!50},
    yticklabels={},
    xticklabels={},
    ytick={1,...,#4}
]
\addplot[draw=none,no marks] coordinates {(0,1) (1e#3,#4)};
\end{axis}
\end{tikzpicture}}
\begin{document}
 \BodeGrid{\textwidth}{0.75\textheight}{6}{9}
\end{document}

enter image description here

  • I didn't realize the syntax for ytick could be so nice (That is, {1,...,#4}). When I posted, I was playing with \for from tikz, which I doubt would have worked. Thanks a lot. – Timtro Mar 22 '15 at 19:54
  • @Timtro My pleasure. – percusse Mar 22 '15 at 19: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.