# pgfplots: Numbers along the x-axis

I'm trying to recreate some Chromatograms (have the tab-separated data) but I need to get numbers along the x-axis with some vertical separation (lines/boxes) as can be seen below

The image was created with a software that ships with the chromatography system but produces rather ugly graphs/plots, I just need the numbers now. Thanks!

-
What do the red numbers refer to? I can't work out how the scale is supposed to read. –  Joseph Wright Nov 28 '11 at 8:04
The x-axis is volume (ml), the red numbers refer to fractions collected by the system. Fraction 1 goes from 0-4ml etc. This is not exported by the software but that would be easy to write in oocalc/excel, question is how do I get pgfplots to draw it in similar fashion. –  user9631 Nov 28 '11 at 8:11

I would suggest you use the extra x ticks option for this. You can supply a list of tick positions using extra x ticks={<list>}, and the corresponding labels using extra x tick labels={<list>}. The style of the extra ticks can be specified using every extra x tick/.style={...}. You can use all the options that are available for "normal" ticks, so you can set x tick label as interval to plot the labels between two tick marks, control the length using major tick length and the style of the tick marks using every tick/.style. The style of the labels can be set using xticklabel style.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=0:30, samples=100,xtick align=outside, enlarge x limits=false, enlarge y limits=upper,
max space between ticks=40,
extra x ticks={0,4,...,30},
extra x tick labels={1,...,7},
every extra x tick/.style={
xtick align=inside,
x tick label as interval=true,
major tick length=5ex,
every tick/.style={
densely dashed,
red,
},
xtick pos=left,
xticklabel style={
red,
anchor=south
}
},
xlabel=Volume / ml,
after end axis/.code={
\node  at (rel axis cs:1,0) [anchor=south west, align=left, red] {Sample\\number};
}
]
\end{axis}
\end{tikzpicture}
\end{document}

-
As a matter of interest, given Joseph's comments, I think this additional "axis", should be annotated, how would you recommend one does this? –  Yiannis Lazarides Nov 28 '11 at 9:17
@YiannisLazarides: I've edited my answer to show what I would do to label the extra ticks. –  Jake Nov 28 '11 at 9:43
This is really great stuff - I will try to implement that. Thanks a lot :) –  user9631 Nov 28 '11 at 9:46
Jake thanks, great answer as always. –  Yiannis Lazarides Nov 28 '11 at 10:01

May be something along these lines could work (see below). It uses pgfplots after and axis code. This way you can use the axis coordinate system. \foreach is explained in the pgfmanual.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
after end axis/.code={%
\foreach \x / \lab in {-4/1,-3/2,-2/3,-1/4,0/5,1/6,2/7,3/8,4/9}%
{\draw[red,dashed] (axis cs: \x,0) -- (axis cs: \x,5);%
\node[xshift=10pt] at (axis cs:\x,3) {\lab};}
}
]