3

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}
2
  • 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, 2013 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. Mar 25, 2013 at 6:40

1 Answer 1

3

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

1
  • 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?
    – 象嘉道
    Mar 25, 2013 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.