TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following code:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[ycomb] plot coordinates
    {(0,3) (1,2) (2,4) (3,1)};
\end{axis}
\end{tikzpicture}
\end{document}

and the output is:

enter image description here

but If I have the coordinates {(a_1,3) (a_2,2) ... (a_i,4) ... (a_r,1)}, with 0 < a_1 < a_2 < ...< a_i < ... < a_r How can I to plot these coordinates?

Thanks in advance!

share|improve this question
up vote 10 down vote accepted

You can use symbolic x coords={...} and xtick=data

Code:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[symbolic x coords={$a_1$,$a_2$,$a_i$,$a_r$},xtick=data,]
\addplot+[ycomb] plot coordinates
    {($a_1$,3) ($a_2$,2) ($a_i$,4) ($a_r$,1)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
thanks soo much! :) – mle Apr 6 '14 at 1:32
    
@Гарнак Олэговытц You are welcome. Have a nice day. :) – Harish Kumar Apr 6 '14 at 1:42

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.