Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a graph with values in xaxis as powers of 2. PGFplots automatically changes the x labels. I want it to use the exact values. What option should I use?

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\pgfplotstableread
{
thread  speedup
1   1
2   3
4   5
8   7
16  7
32  7
64  8
128 9
}\datafile
\begin{tikzpicture}
    \begin{axis}
    [
        title=test
        ,xlabel=size
        ,ylabel=Througput
    ]
    \addplot table[x=thread,y=speedup,color=red,mark=x] {\datafile};
    \end{axis}
\end{tikzpicture}
\end{document}

output

share|improve this question

1 Answer 1

up vote 6 down vote accepted

If you add xtick=data then only the data points are taken as tick values. And you get

enter image description here

Instead you can use the loagrithmic axis for x values and change the base of logarithm to 2 via adding log basis x key.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotstableread
{
thread  speedup
1   1
2   3
4   5
8   7
16  7
32  7
64  8
128 9
}\datafile

\begin{document}
\begin{tikzpicture}
    \begin{semilogxaxis}
    [
        title=test
        ,xlabel=size
        ,ylabel=Througput,xtick=data,log basis x=2
    ]
    \addplot table[x=thread,y=speedup,color=red,mark=x] {\datafile};
    \end{semilogxaxis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thank you. I actually tried both the versions. Version 1 has all the x ticks but it automatically scales the xaxis. In version 2 as log axis is used, scaling is even, but the numbers are displayed in powers of 2. So I modified version 1 to include symbolic x coords={1,2,4,8,16,32,64,128} so that it doesn't scale the axis –  arunmoezhi Jul 20 at 19:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.