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.

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

3 Answers 3

up vote 15 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
    
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

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

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

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.