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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Now the numbers on the x-axis are

0, 0.5, 1, 1.5, 2

I want to show integer only:

0, 1, 2

How can I do that? My code:

\begin{tikzpicture}
\begin{axis}[
    xlabel=threads,
    ylabel=speedup & deviation]
\addplot table[x=thread,y=speedup] {datafile.dat};
\addplot table[x=thread,y=dev] {datafile.dat};
\end{axis}
\end{tikzpicture}

The content of datafile.dat:

thread  speedup dev
1   1   0
2   3   1
3   5   0
4   7   1
share|improve this question
2  
For example, you can include a compilable minimal code and we can have a look together :) – percusse Mar 9 '12 at 2:37
up vote 23 down vote accepted

If you want to have the x ticks to appear exactly as entered you can use the option xtick=data.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\pgfplotstableread{
thread  speedup dev
1   1   0
2   3   1
3   5   0
4   7   1
}\datafile

\begin{tikzpicture}
\begin{axis}[
    xlabel=threads,
    ylabel=speedup \& deviation,
    xtick=data]
\addplot table[x=thread,y=speedup] {\datafile};
\addplot table[x=thread,y=dev] {\datafile};
\end{axis}
\end{tikzpicture}
\end{document}

or you can enter manually by xtick={1,2,3,4} option

share|improve this answer
1  
This wouldn't be ideal with large sets of data. – Magpie Mar 12 '13 at 20:01
    
@Magpie then you use explicit ticks or leave it to pgfplots anyway. – percusse Mar 12 '13 at 22:41

Use xtick={0, 1, 2} to specify where you want the xticks:

enter image description here

Notes:

  • This also necessitated specifying xmin=0 to get the marker for x=0.
  • You also need to \& for the ylabel.

Code:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents*}{datafile.dat}
thread  speedup dev
1   1   0
2   3   1
3   5   0
4   7   1
\end{filecontents*}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xlabel=threads,
    ylabel={speedup \& deviation},
    xtick={0, 1, 2},
    xmin=0
]
\addplot table[x=thread,y=speedup] {datafile.dat};
\addplot table[x=thread,y=dev] {datafile.dat};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer

Section 4.14 of the pgfplots manual describes the xtick option, which gives a list of locations for the ticks. In this case xtick={1,...,4} should do the trick.

Here's an example:

\documentclass{article}
\usepackage{pgfplots}

% example data file
\usepackage{filecontents}
\begin{filecontents}{datafile.dat}
thread speedup dev
1 1 0
2 3 1
3 5 0
4 7 1
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xlabel=threads,
    ylabel=speedup \& deviation,
    xtick={1,...,4}]

\addplot table[x=thread,y=speedup] {datafile.dat};
\addplot table[x=thread,y=dev] {datafile.dat};
\end{axis}
\end{tikzpicture}
\end{document}

(EDIT: Different section numbers for difference versions of the manual)

share|improve this answer
    
What about axis that go from -4 to 4? – Magpie Mar 12 '13 at 20:01

If you want to specify the step, i.e. the interval of your ticks, you can also use the xtick distance-option. Refer to section 4.15 in the pgfplots manual, Version 1.13. As @Magpie pointed out, this one is easier to use than xtick if use have a large number of ticks you want to show.

Code

\documentclass{minimal}
\usepackage{pgfplots}

% example data file
\usepackage{filecontents}
\begin{filecontents}{datafile.dat}
    thread speedup dev
    1 1 0
    2 3 1
    3 5 0
    4 7 1
\end{filecontents}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=threads,
        ylabel=speedup \& deviation,
        xtick distance=1
        ]

        \addplot table[x=thread,y=speedup] {datafile.dat};
        \addplot table[x=thread,y=dev] {datafile.dat};
    \end{axis}
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
    
Welcome to TeX - LaTeX! Can you provide some sample code showing this in action. – Andrew Swann Apr 17 at 10:08

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.