1

I'm currently using the semilogy environment and wondering on how to control whether they actually take 10 log or 20 log.

  • The option log basis y=20 might be related. But I am unsure of what you mean by "actually take". Could you write a minimal working example and more details on what you want to achieve? – Christian Feuersänger May 24 '14 at 18:58
  • Assuming I have some data x, I want to plot either 10*log10(x) or 20*log10(x). When I read through your manual of pgf, I thought that the 'log basis' command handles whether it takes natural logarithm or dual logarithm etc, but not the multiplier. Please see also my first try( answer) maybe this clarifies what I mean. – bonanza May 24 '14 at 20:28
  • 1
    Ok. In this case, y filter is what you need. But the input argument to y filter already has the log applied (namely the one defined by log basis y which is e by default). Consequently, you would need \pgfmathparse{20*\pgfmathresult} since \pgfmathresult already contains log_b(y). The result appears to be useless, though: 20*log(y) = log(y^20). If y=10^{-5} and log basis y=10, you receive 20*log(y) =-100 which corresponds to a value 10^{-100}. Is this what you want!? – Christian Feuersänger May 24 '14 at 21:43
  • But does it always include the logarithm or only when I'm in semilogy environment? Because I tried to apply the filter without logarithm, just as you said, to the semilogy environment and it seems that the filter is applied before taking the logarithm which gives a different result. – bonanza May 25 '14 at 6:29
  • @ChristianFeuersänger sorry, please ignore my previous comment. I was in a rush and havent read your comment correctly.Yes this is exactly what I want! and If I do it as you propose, I can stay with 'semiglogy' environment, right? Does this have any advantage over applying my 'fix' to the 'axis' environment? – bonanza May 25 '14 at 8:44
3

Your approach to rely on y filter is correct in this case. However, it operates on different values depending on whether you have a log axis or a linear one: a log axis provides the log of the value as input to y filter. Since you explicitly want a log basis 10, you need to specify log basis y=10 for a log axis (otherwise you'll have log basis e).

The difference between a linear axis with a filter which applies log and a log axis which multiplies values by 20 is just in the axis descriptions.

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{compat=1.9}

\begin{document}

\begin{tikzpicture}
    \begin{axis}
    \addplot+[
        y filter/.code={\pgfmathparse{20*log10(\pgfmathresult)}},
    ]
    {10^x};
    \end{axis}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{semilogyaxis}[
        log basis y=10,
        ytickten={-100,-50,...,100},
    ]
    \addplot+[
        y filter/.code={\pgfmathparse{20*\pgfmathresult}},
    ]
    {10^x};
    \end{semilogyaxis}
\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||
2

My own solutions as style for the normal axis environment:

every axis plot/.style={ y filter/.code={\pgfmathparse{20*log10(\pgfmathresult)}\pgfmathresult} },
|improve this answer|||||
  • It seems as if this is actually part of the question. In this case, you should put your remark into the question and state some thing like "from what I understood, this here should do the job but it doesn't" and ask for help. If you post an answer (as here), others will assume that the question is answered and you just wanted to share your insight. In addition, it will significantly help if you add a complete minimal working example to your question. – Christian Feuersänger May 24 '14 at 21:46
  • Ok, this is really what you wanted achieve. You should eliminate the final \pgfmathresult as it will result in lots of warnings in your .log file. – Christian Feuersänger May 25 '14 at 16:31

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.