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 a set of numbers as x-coordinates:{2.08, 2.09, 2.7, 4.9, 12.8, 29.3, 64.2}. the left part of the diagram is too tight because 2.08 and 2.09 are very close. i want to evenly distribute the set of numbers on x-axis. is it possible? and how? see an example as follows:

\begin{figure}[!h]
  \centering
      \caption{The example.}
      \label{figure:the_example}
      \begin{tikzpicture}[scale=0.45]
        \begin{axis}[ybar,xtick=data,xlabel=$ \lambda $,ylabel=$ \alpha $,
                      x tick label style={rotate=-35,anchor=west},width=2.2\textwidth,
                      height=0.32\textheight,legend pos=north west,ymin=0]
          \addplot coordinates {
            (2.08,10)
            (2.09,15)
            (2.7,25)
            (4.9,22)
            (12.8,21)
            (29.3,12)
            (64.2,17)
          };
        \end{axis}
      \end{tikzpicture}
\end{figure}
share|improve this question
8  
Can you post your plot with the tight version? It's really not fun to setup a MWE from scratch just to test a key for you. –  percusse Mar 24 '13 at 23:48
    
It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that illustrates the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. –  Peter Grill Mar 25 '13 at 6:40

1 Answer 1

You can use symbolic x coords:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}[scale=0.45]
\begin{axis}[
  ybar,
  xlabel=$\lambda$,ylabel=$\alpha$,
  symbolic x coords={2.08,2.09,2.7,4.9,12.8,29.3,64.2},
]
\addplot coordinates {
  (2.08,10)
  (2.09,15)
  (2.7,25)
  (4.9,22)
  (12.8,21)
  (29.3,12)
  (64.2,17)
};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
thank you very much. it works. i also need to draw a red line, y = 12, with the code:\addplot[red,sharp plot,update limits=false] coordinates {(-16,12) (32,12)};. how should i integrate the red line code with symbolic coords? –  xando Mar 25 '13 at 17:34

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.