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.

Given a set of (x,y) coordinates stored in a file, how could I generate a stem plot from those coordinates? I would like to achieve something similar as the matlab's stem function: http://www.mathworks.ch/help/techdoc/ref/stem.html I found a nice tutorial on how to generate 2d plots, but the points are interpolated: http://d.xav.free.fr/tikz/index.html

share|improve this question
1  
Take a look at the ycomb plot option from pgfplots. –  Roelof Spijker Mar 16 '12 at 11:06
add comment

1 Answer 1

up vote 8 down vote accepted

Package pgfplots is a good replacement for gnuplots and Matlab figures. Here you have an example. It's easy to understand its manual.

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\begin{filecontents*}{datafile.dat}
3.045784        3.415896
3.405784        4.025693
3.785784        4.522530
4.125784        5.538449
4.485784        6.704992
4.805784        6.978939
5.145784        7.113496
5.425784        8.916397
6.065784        9.487712
6.365784        10.876397
6.685784        10.693497
7.025784        11.364131
7.345784        11.442530
7.665784        12.582530
8.005784        13.125693
8.225784        13.738450
8.585784        14.247891
8.865784        14.982530
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[ycomb] plot table[x expr=\coordindex+1, y index=0]{datafile.dat};
\addplot+[ycomb] plot table[x expr=\coordindex+1, y index=1]{datafile.dat};
\end{axis}
\end{tikzpicture}
\end{document}

The result is

enter image description here

If you are already using Matlab, matlab2tikz will be a good tool.

share|improve this answer
add comment

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.