2

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!

opieters
  • 261
  • Welcome to TeX.SX! This should help you out: http://tex.stackexchange.com/a/139084/21344 – Paul Gessler Mar 01 '14 at 21:34
  • Welcome to the site! Your snippet helps, but it'd be great if you turn it into a complete MWE so that folks don't have to construct anything :) Have you tried yticklabels={10,15,20,25,30}? – cmhughes Mar 01 '14 at 21:35
  • Thanks for your quick responses! Oh, I'll mind that next time. I'm quite new to LaTeX and this forum so I still have a lot to learn :) – opieters Mar 01 '14 at 23:09

2 Answers2

5

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

percusse
  • 157,807
  • This achieves the desired result, but scientifically is very wrong. Units should be marked as "dB" and for dB units, the yscale is linear, using a logarithmic grid is not correct. – Xaser Mar 16 '24 at 13:30