0

I'm working on a (magnitude) Bode plot and for some reason the x-axis wont go into log mode. I would like the x-axis to go from 10Hz to 200Hz. When I change xmax=1000 the plot is in the right format, but not the right axis range. If I then change back to xmax=200 the x-axis is no longer in log mode. Also the ticks change when I go to xmax=200. (I would only like 10^1, 10^2 but with xmax=200 the ticks 10^1.1, 10^1.2 etc. appear)

Here is my code (I've omitted the data). Hope it is readable, copying from texstudio to this post completely messes up the formatting.

\documentclass[]{article}
\usepackage{pgfplots}

\begin{document}

\begin{figure}[]

\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}
\definecolor{mycolor4}{rgb}{0.49400,0.18400,0.55600}

\begin{tikzpicture}

\begin{axis}[
width=12.8cm,
height=3cm,
at={(0.596in,1.66in)},
scale only axis,
separate axis lines,
every outer x axis line/.append style={white!40!black},
every x tick label/.append style={font=\color{white!40!black}},
xmode=log,
xmin=10,
xmax=200,
xlabel={Frequency (Hz)},
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={white!40!black},
every y tick label/.append style={font=\color{white!40!black}},
ymin=-80,
ymax=0,
ylabel={Magnitude (dB)},
ymajorgrids,
axis background/.style={fill=white},
legend style={legend pos=south west,legend cell align=left,align=left,draw=white!15!black}
]

\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}
2

I think you get the undesired result because of (at least for a log plot) the very small x range. To overcome this issue you can add the xticks yourself/by hand, either by using the xtickten key, which requires fewer computational time or by using xtick itself.

(Please note that I reduced your code to the absolute minimum - so it is now a real MWE - so the key point can be tracked more easily.)

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            xmin=10,
            xmax=200,
            xmode=log,
            xtickten={1,2},     % <-- added
        ]
            % just a dummy plot so `xticks' show up as wanted
            \addplot+ [domain=10:200] {log10(x)};
        \end{axis}
    \end{tikzpicture}
\end{document}

image showing the result of above code

  • yeah xtickten does exactly what I want. Thank you!!! – Niwol Nov 2 '16 at 14:04

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.