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.

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)
};
\addplot[dashed] coordinates {(-1,0) (42,0)};
\end{axis}
\end{tikzpicture}%
}
\end{sidewaysfigure}
\end{document}
share|improve this question

2 Answers 2

up vote 7 down vote accepted

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,
  xticklabels={Duck happy,Cat happy,Octopus happy,Monkey happy, Human happy,Duck sad,Cat sad,Octopus sad,Monkey sad, Human sad},xtick={1,...,10},
  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)
};
\addplot[dashed] coordinates {(0,0) (10.5,0)};
\end{axis}
\end{tikzpicture}%

\end{sidewaysfigure}
\end{document}

output of code

share|improve this answer
    
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

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)
        };
        \addplot[dashed] coordinates {(A,0) (J,0)};
      \end{axis}
    \end{tikzpicture}%
  \end{sidewaysfigure}
\end{document}

enter image description here

share|improve this answer
    
Donig Thanks for that! However, I'm not sure if this has got me a lot further along. The labels I am using are not as simple as Picture A, Picture B, but more like "Reindeer 1", "Octopus 2", "Human Face". Your way is neat, but I'm still at a loss to use arbitrary labels. –  Frank_Zafka Jun 3 '11 at 12:29
    
@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
    
@Christoph I have added some labels above. I can have them in whatever format is needed. I can't see how to replace the numbers with the labels though--that's where I'm stuck! –  Frank_Zafka Jun 3 '11 at 13:39
    
@RSoul There's a simpler way to do this without the use of symbolic coordinates; see my answer. This solves the zero line problem too. –  Alan Munn Jun 3 '11 at 14:13
    
@RSoul: My solution is based on the originally given information. I had no time to react on the modifications of your demands. In the meantime you've got an appropriate solution. –  Thorsten Donig Jun 4 '11 at 8:51

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.