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}

1 Answer 1

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .