5

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!

1 Answer 1

6

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

1
  • @Гарнак Олэговытц You are welcome. Have a nice day. :)
    – user11232
    Apr 6, 2014 at 1:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .