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 finally managed to center my data with axis x line*=center, but I haven't found a way to get my x tick labels at the bottom of the figure. I have already drawn some major grid lines and now I want my tick labels to be at the bottom of my figure.

I have tried to use at={()}, but that did not seem to work.

The tick labels are now on the axis.

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \pgfplotstableread{data/multicontrol.dat}\datatable

    \begin{axis}[ybar=0,
    bar width={0.2cm},
    xticklabels from table={\datatable}{variable},
    xtick=data,
    x tick label style={
        rotate=60,anchor=east},
    yticklabels={X,Very Bad, Bad, Neutral, Good, Very Good},
    xmajorgrids,
    ymin=-2,
    ymax=2,
    axis x line*=middle,
    axis y line*=left,
    enlarge x limits,
    y filter/.code={\pgfmathparse{#1-3}}
    ]

    \addplot table[x=X,y=old] {\datatable};
    \addlegendentry{Joystick}
    \addplot table[x=X,y=new] {\datatable};
    \addlegendentry{Mouse}
    \end{axis}
\end{tikzpicture}
\end{document}

Example data:

X   variable                    old         new
1   {Know where I am}           2.375       4
2   {Know what I see}           3.375       4.375
3   {See target directly}       2.428571429 4.5
4   {Know origin}               3.875       4.285714286
5   {Direct Adjustment (inv)}   2.625       3.75
6   {Screen position}           3.25        4.125
7   {Expectation}               2.25        2.375
8   {Get lost (inv)}            2.714285714 3.5
9   {Number dependent (inv)}    2           4
share|improve this question

1 Answer 1

up vote 13 down vote accepted

The easiest thing to do here is to use axis x line*=left (instead of middle), which will place the axis line and the labels at the bottom of the plot, and to "fake" the zero line using one of the approaches from How can I add a zero line to a plot?.


For this graph, may I suggest flipping the axes around? That would make it much easier to read the labels, since you can do without the rotation:


Code for first solution

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \pgfplotstableread{
X   variable                    old         new
1   {Know where I am}           2.375       4
2   {Know what I see}           3.375       4.375
3   {See target directly}       2.428571429 4.5
4   {Know origin}               3.875       4.285714286
5   {Direct Adjustment (inv)}   2.625       3.75
6   {Screen position}           3.25        4.125
7   {Expectation}               2.25        2.375
8   {Get lost (inv)}            2.714285714 3.5
9   {Number dependent (inv)}    2           4
}\datatable

    \begin{axis}[ybar=0,
    bar width={0.2cm},
    xticklabels from table={\datatable}{variable},
    xtick=data,
    x tick label style={
        rotate=60,anchor=east},
    yticklabels={X,Very Bad, Bad, Neutral, Good, Very Good},
    xmajorgrids,
    ymin=-2,
    ymax=2,
    axis x line*=left,
    axis y line*=left,
    enlarge x limits,
    y filter/.code={\pgfmathparse{#1-3}},
    after end axis/.code={\draw ({rel axis cs:0,0}|-{axis cs:0,0}) -- ({rel axis cs:1,0}|-{axis cs:0,0});}
    ]

    \addplot table[x=X,y=old] {\datatable};
    \addlegendentry{Joystick}
    \addplot table[x=X,y=new] {\datatable};
    \addlegendentry{Mouse}
    \end{axis}
\end{tikzpicture}
\end{document}

Code for second solution

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \pgfplotstableread{
X   variable                    old         new
1   {Know where I am}           2.375       4
2   {Know what I see}           3.375       4.375
3   {See target directly}       2.428571429 4.5
4   {Know origin}               3.875       4.285714286
5   {Direct Adjustment (inv)}   2.625       3.75
6   {Screen position}           3.25        4.125
7   {Expectation}               2.25        2.375
8   {Get lost (inv)}            2.714285714 3.5
9   {Number dependent (inv)}    2           4
}\datatable

    \begin{axis}[xbar=0,
    bar width={0.2cm},
    yticklabels from table={\datatable}{variable},
    ytick=data,
    xticklabels={X,Very Bad, Bad, Neutral, Good, Very Good},
    xmajorgrids,
    xmin=-2,
    xmax=2,
    axis x line*=left,
    axis y line*=left,
    enlarge x limits,
    x filter/.code={\pgfmathparse{#1-3}},
    after end axis/.code={\draw ({rel axis cs:0,0}-|{axis cs:0,0}) -- ({rel axis cs:0,1}-|{axis cs:0,0});},
    legend style={at={(1,0.9)}}
    ]

    \addplot table[y=X,x=old] {\datatable};
    \addlegendentry{Joystick}
    \addplot table[y=X,x=new] {\datatable};
    \addlegendentry{Mouse}
    \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
I would like to know if I'm doing a good job inserting yticklabels={X,Very Bad, Bad, Neutral, Good, Very Good}. It seems a little hacky with the X in front, but that was the only way to get it working somehow. –  Marnix Jun 16 '12 at 15:37
1  
@Marnix: You can avoid the dummy label by specifying the y tick positions: ytick={-2,...,2}, yticklabels={Very Bad, Bad, Neutral, Good, Very Good} –  Jake Jun 16 '12 at 15:40

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.