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!

3
  • Welcome to TeX.SX! This should help you out: tex.stackexchange.com/a/139084/21344 Mar 1 '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 1 '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 1 '14 at 23:09
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

1

You can try the bodegraph package (http://www.ctan.org/pkg/bodegraph)

Some example here (http://sciences-indus-cpge.papanicola.info/Bode-Black-et-Nyquist-avec-Tikz) and here http://www.texample.net/tikz/examples/bode-plot/

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.