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 plot a few data sets into the same chart using pgfplot and I therefore use \pgfmathparse to offset every plot a bit to the left or the right.

I found out that the first plot will always be the center of the tick thus I created a invisible center around which the others can be placed.

However this causes an extra tick to appear for the most left plot. The image below shows that the first a,b,c,d should not appear and the second tick is the correct one just right in the middle.

Plot example

How could I remove this tick? I can remove the letter by using explicit xticklabels but the tick line still remains.

Below is a minimal example:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{testdata.csv}
var range1 range2
a 1 2
b 1 1
c 3 4
d 1 2
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
        \begin{axis}[
            xtick=data,
            symbolic x coords={a,b,c,d}
        ]
        \addplot +[only marks, forget plot, no markers]
            table[x=var, y=range1]{testdata.csv};% the first plot is the center
        \addplot +[only marks, x filter/.code=\pgfmathparse{\pgfmathresult-0.2}]
            table[x=var, y=range1]{testdata.csv};
        \addplot +[only marks, x filter/.code=\pgfmathparse{\pgfmathresult+0.2}]
            table[x=var, y=range2]{testdata.csv};
        \end{axis}
\end{tikzpicture}
\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

xtick=data will set an xlabel for every data point, which you do not want in this example. In this particular case, you can just remove xtick=data and the correct labels will be set. In your real case, however, you might want to explicitly set the labels using something like xtick={a,b,c,d}. You might also want to set the text height of the x tick label style explicitly to something like 2ex to get the vertical placement of the letters right:

 \documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\begin{filecontents*}{testdata.csv}
var range1 range2
a 1 2
b 1 1
d 1 2
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
        \begin{axis}[
            symbolic x coords={a,b,c,d},
            xtick={a,b,c,d},
            x tick label style={text height=2ex}
        ]
        \addplot +[only marks, x filter/.code=\pgfmathparse{\pgfmathresult-0.2}]
            table[x=var, y=range1]{testdata.csv};
        \addplot +[only marks, x filter/.code=\pgfmathparse{\pgfmathresult+0.2}]
            table[x=var, y=range2]{testdata.csv};
        \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.