# Pgfplots: Replace x-axis numbering with labels on confidence interval plot?

Try as I might, I can't seem to replace the numbering on the x-axis with (arbitrary) labels.

Here is a half-and-half, where the plot has been done in PGPPlots and I've added two of the x-ticks showing how I'd like it to look: I've seen a few examples in relation to barplots, but I can't seem to transfer it to this example. As always, thanks for the consideration.

Update: Got it working with a combination of scale and width. Thanks all.

MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{rotating}
\usepackage{verbatim}
\usepackage{pgfplots}
\begin{document}
\begin{sidewaysfigure}
\begin{tikzpicture}[scale=1.1],
\centering
\begin{axis}[
height=8cm,
width=15cm,
ymax=5,
ymin=-3,
xmin=0.5,
xmax=10.5,
axis y line*=left,
axis x line*=bottom]
\addplot+[only marks][error bars/.cd,y dir=both, y explicit]
coordinates {
(10,0.23333) +- (0.58257,-0.1159)
(9,1.4) +- (2.04003,0.75997)
(8,1.1) +- (1.82293,0.37707)
(7,1.3667) +- (2.0352,0.6981)
(6,0.26667) +- (0.94558,-0.41225)
(5,0) +- (0.59648,-0.59648)
(4,0.9) +- (1.67431,0.12569)
(3,-0.66667) +- (0.09502,-1.42835)
(2,0.56667) +- (1.30495,-0.17162)
(1,0.4) +- (1.06941,-0.26941)
};
\end{axis}
\end{tikzpicture}%
}
\end{sidewaysfigure}
\end{document}

-

You can use anything as symbolic coordinates: (In fact, the coordinates themselves can be just A,B,C, D etc.) But for your solution, you just need to map the xtick labels. Based on Jakes comment, I've also added xtick={1,...,10} to explicitly map the ticks to the labels.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{rotating}

\begin{document}
\documentclass{article}
\usepackage{tikz}
\usepackage{rotating}
\usepackage{verbatim}
\usepackage{pgfplots}
\begin{document}
\begin{sidewaysfigure}
\begin{tikzpicture}[scale=1.1],
\centering
\begin{axis}[
height=8cm,
width=15cm,
ymax=5,
ymin=-3,
xmin=0.5,
xmax=10.5,
axis y line*=left,
axis x line*=bottom,
x tick label style={rotate=90,anchor=east}]
\addplot+[only marks][error bars/.cd,y dir=both, y explicit]
coordinates {
(10,0.23333) +- (0.58257,-0.1159)
(9,1.4) +- (2.04003,0.75997)
(8,1.1) +- (1.82293,0.37707)
(7,1.3667) +- (2.0352,0.6981)
(6,0.26667) +- (0.94558,-0.41225)
(5,0) +- (0.59648,-0.59648)
(4,0.9) +- (1.67431,0.12569)
(3,-0.66667) +- (0.09502,-1.42835)
(2,0.56667) +- (1.30495,-0.17162)
(1,0.4) +- (1.06941,-0.26941)
};
\end{axis}
\end{tikzpicture}%

\end{sidewaysfigure}
\end{document}


-
I just spent the last two hours upgrading my texlive (for the second time in the week). And I just worked out symbolic coordinates can be arbitrary too. Thanks. –  Frank_Zafka Jun 3 '11 at 14:07
@RSoul, you don't need to do it the way I initially did it, you can just map your numeric values onto xtick labels. See my revised solution which is almost identical to your initial code. –  Alan Munn Jun 3 '11 at 14:12
Let me have a work with it all. My REAL example has 42 labels...phew...Thanks all. –  Frank_Zafka Jun 3 '11 at 14:20
The solution should be the same. (The method is essentially the same as is used in R). The only odd think to watch out for is the two initial commas in the xtick labels list. –  Alan Munn Jun 3 '11 at 14:24
@RSoul, @Alan: If you add the line xtick={1,...,10}, (or xtick={1,...,42}, in you real application) to the axis options, you can get rid of the two initial commas. If you don't specify the ticks explicitly, PGFplots will map the tick labels to ticks that aren't necessarily shown in the plot. –  Jake Jun 3 '11 at 22:04
show 1 more comment

This approach comes pretty close. But it is not perfect since the zero x line only connects the first and last x value, thus is not passing the whole plot.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{rotating}

\begin{document}
\begin{sidewaysfigure}
\centering
\begin{tikzpicture}[scale=1.1]
\begin{axis}[%
height=8cm,
width=15cm,
%        xmin=0.5,
%        xmax=10.5,
ymax=5,
ymin=-3,
axis y line*=left,
axis x line*=bottom,
symbolic x coords={A,B,C,D,E,F,G,H,I,J},
x tick label style={rotate=90,anchor=east},
xticklabel={Picture~\tick}
]
\addplot+[only marks][error bars/.cd,y dir=both,y explicit] coordinates {%
(J,0.23333) +- (0.58257,-0.1159)
(I,1.4) +- (2.04003,0.75997)
(H,1.1) +- (1.82293,0.37707)
(G,1.3667) +- (2.0352,0.6981)
(F,0.26667) +- (0.94558,-0.41225)
(E,0) +- (0.59648,-0.59648)
(D,0.9) +- (1.67431,0.12569)
(C,-0.66667) +- (0.09502,-1.42835)
(B,0.56667) +- (1.30495,-0.17162)
(A,0.4) +- (1.06941,-0.26941)
};

@RSoul Where do your labels come from? Is everything in a big data file, like a csv created from a spreadsheet? It might be possible to use the pgfplotstable package to extract the labels and data. –  Christoph Jun 3 '11 at 13:23