[Tex/LaTex] Log scale with integer numbers on y-axes

pgfplotstikz-pgf

I'm writing a report and one of the requirement of my Bode-plots is that they are logarithmic, but I need integer numbers (i.e. 10, 20 and 30) on the y-axes.

I tried using ytick={} but these numbers do not appear in the graph.

Part of my code:

\begin{tikzpicture}
\begin{loglogaxis}[
    xlabel=frequentie $f (\hertz)$,
    ylabel=weerstand $R (\ohm)$,
    grid=both, 
    minor grid style={gray!25}, 
    major grid style={gray!25},
    ytick={10,15,20,25,30}]
\addplot table[x=f,y=R,col sep=semicolon]{MeetresultatenOpdracht12a.csv};
\end{loglogaxis}
\end{tikzpicture}

Thanks!

Best Answer

Here is a style example for Bode plots, though you have Ohm as the y-axis unit. In the label computation, \tick already holds the logarithmic value depending on the base we have set. Hence if you simply pretty print with the option fixed you get the desired value. Otherwise using an exponential function you can convert it to the original value.

\documentclass{standalone}
\usepackage{pgfplots,siunitx}
\pgfplotsset{compat=1.9}
\usepgfplotslibrary{units}

\begin{document}

\begin{tikzpicture}
\begin{loglogaxis}[
  enlargelimits=false,
  grid=both,
  ymin=5e-6,ymax=2,
  xlabel= Frequency,
  ylabel= R,
  x unit=\si{\hertz},
  y unit=\si{\ohm},
  log basis y=10,
  log basis x=10,
  %dB definition taken as 20 log10(x)
  yticklabel={\pgfmathparse{20*(\tick)}\pgfmathprintnumber[fixed]{\pgfmathresult}},
  domain=1e-7:1e1,samples=250
]
\addplot+[no marks,thick]{exp(-5*x)};
\end{loglogaxis}
\end{tikzpicture}
\end{document}

enter image description here

Related Question