3

I am trying to plot some data with on logarithmic axes. My x axis is labelled with integer numbers from the input data (xtick=data). I don't want to use scientific notation, so I added the log ticks with fixed point option. However, the tick labels are rounded and have a precision of only 3 digits.

screenshot of example

I have tried to solve this problem in 2 ways. First: changing the x tick label style with formatting options. See the example below.

\begin{tikzpicture}
    \begin{loglogaxis}[
        log ticks with fixed point,
        x tick label style={/pgf/number format/fixed relative,/pgf/number format/precision=5},
        xtick=data,
        ]
            \addplot table[x=input,y=output] {
                input   output
                1   0.9
                16  4
                256 9
                4096    15
                65536   20
            };
    \end{loglogaxis}
\end{tikzpicture}

My second attempt was to recalculate the labels based on this answer and this answer. This leads to some errors in the floating point calculation, since the example below results in the label '33442' instead of '33444'.

\begin{tikzpicture}
    \begin{loglogaxis}[
        log ticks with fixed point,
        log basis x=2,
        xticklabel={
            \pgfkeys{/pgf/fpu=true}
            \pgfmathparse{2^\tick}
            \pgfmathprintnumber[fixed]{\pgfmathresult}
        },
        xtick=data,
        ]
            \addplot table[x=input,y=output] {
                input   output
                1   0.9
                16  4
                256 9
                4096    15
                33444   20
            };
    \end{loglogaxis}
\end{tikzpicture}

How can I solve this problem and display the numbers exactly as they are in my data?

Thomas
  • 151
  • Related (duplicate?): http://tex.stackexchange.com/questions/287196/pgfplots-logarithmic-scale-showing-1020-insteead-of-1024 – Jake May 13 '16 at 09:55
  • Thanks Jake, with the information in your answer there, I was able to solve my problem. One remark: the solution with recomputing the xticklabel is not very general, it does not apply to random/non regular input. In case there is no answer in one day, I will delete this question, since it is indeed a duplicate. – Thomas May 13 '16 at 10:56
  • @Thomas: I'm not sure I understand what you mean by "it does not apply to random/non regular input". Could you edit your question to include an example where the linked answer fails? – Jake May 13 '16 at 12:04
  • @Jake: I have edited my question. In the meantime, I have also found another solution with xticklabels from table, which I will put in an answer. – Thomas May 13 '16 at 12:17
  • @Thomas: Ah yes, I see! Good point, and good idea using xticklabels from table instead – Jake May 13 '16 at 12:28

1 Answers1

2

In this case, an easy solution is to use the attribute xticklabels from table, since the input data is in table format:

\begin{tikzpicture}
    \begin{loglogaxis}[
        log ticks with fixed point,
        xtick=data,
        xticklabels from table={data.dat}{input},
        ]
            \addplot table[x=input,y=output] {data.dat};
    \end{loglogaxis}
\end{tikzpicture}

where data.dat contains:

input   output
1   0.9
16  4
256 9
4096    15
33444   20

This gives the desired result:

enter image description here

Thomas
  • 151