[Tex/LaTex] how does xscale & yscale work in TiKZ

bodegraphtikz-pgf

I am trying to read the documentation for bodegraph package (it´s in french!), right away the third example uses a code to generate two grids for two plots. Heres the MWE and a picture:

\documentclass{article}
\usepackage{tikz}

\usepackage{bodegraph}

\begin{document}

\begin{tikzpicture}[xscale=7/5]
\begin{scope}[yscale=3/80]
\UnitedB
\semilog{-1}{4}{-60}{20}
\end{scope}
\begin{scope}[yshift=-3cm,yscale=3/180]
\UniteDegre
\OrdBode{30}
\semilog{-1}{4}{-180}{0}
\end{scope}
\end{tikzpicture}

\end{document}

A grid for bode diagrams

In my opinion they look very tiny but I can´t understand how xscale=m/n or yscale=p/r works. I would truly appreciate if someone explained me how to make them as width as 0.5\textwidth or \textwidth and also make them have the same height.

Thanks in advance

Best Answer

xscale and yscale are both simply scaling factors.

While I haven't looked at the code, it looks like bodegraph has as default 1 unit between the major gridlines on the x-axis (each order of magnitude). And as your diagram covers five orders of magnitude, xscale=7/5 will give a diagram that is 7 units wide, plus the width of the axis labels. The default unit vectors in TikZ are 1cm long, so 7 units is 7cm.

For y it looks like there is no scaling done initially, so without yscale, a diagram that ranges from -60 to 20 will be 80 units (80cm) high. Hence, yscale=3/80 gives an axis that is 3cm high.

Both your diagrams have the same height, because the first one has a range of 80 and yscale=3/80, while the second has a range of 180 and yscale=3/180.

If you want to set the width relative to \textwidth, you can do something like the following. The \pgfmathsetmacro is not strictly necessary, you can put the entire calculation directly into yscale.

\documentclass{article}
\usepackage{showframe}

\usepackage{bodegraph}
% use 0.85 to allow for axis labels
\pgfmathsetmacro{\textwidthScaleFactor}{0.85\textwidth*2.54/72.27}
\begin{document}
\begin{center}
% diagram covers 5 orders of magnitude, so 1/5
\begin{tikzpicture}[xscale=1/5*\textwidthScaleFactor]
\begin{scope}[yscale=3/80]
\UnitedB
\semilog{-1}{4}{-60}{20}
\end{scope}
\begin{scope}[yshift=-3cm,yscale=3/180]
\UniteDegre
\OrdBode{30}
\semilog{-1}{4}{-180}{0}
\end{scope}
\end{tikzpicture}
\end{center}
\end{document}