19

I have made a chart using pgfplots as written below and I want to have the y-axis in logarithmic scale. This code works fine but the base of the logarithm is 10. How can I change it to base 2?

\begin{tikzpicture}
    \begin{axis}[
        height=0.5\textwidth,
        width=\textwidth,
        xlabel=LabelX,
        xtick={1,...,10},
        ylabel=LabelY,
        ymode=log,
    ]
        \addplot[mark=*,blue] table[x=V,y=R] {data1.data};
        \addplot[mark=x,red] table[x=V,y=E] {data2.data};
    \end{axis}
\end{tikzpicture}
24

You can use the log basis x={<number>} and/or log basis y={<number>} options:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        height=0.5\textwidth,
        width=\textwidth,
        xlabel=LabelX,
        xtick={1,...,10},
        ylabel=LabelY,
        ymode=log,
       log basis y={2}
]
        \addplot[mark=*,blue] coordinates {(2,2) (5,8) (7,16)};
    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • Is it possible to keep the nice "inbetween" log ticks for the logarithmic axis when doing this? – rubdos May 14 '18 at 16:43

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.