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 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

1 Answer 1

up vote 9 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 at 1:32
    
@Гарнак Олэговытц You are welcome. Have a nice day. :) –  Harish Kumar Apr 6 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.