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 wish to draw something like (a kind of rug plot) enter image description here

The plot shows performance of various machine learning methods. I wonder what is the best way to draw perpendicular hooks. Moreover, how can I automatize hook drawing.

Any idea is greatly appreciated.

Minimal working example is pasted below.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]

% Axis
\draw[-] (0,0) -- (5,0);
% Coordinates
\node (A) at (3,0) {};
\node (B) at (2,0) {};
\node (C) at (2.5,0) {};

% Lines
\draw (A) -| ++(0,-0.5)-| ++(2,0) node (n1) [right] {LDA};
\draw (B) -| ++(0,-0.5)-| ++(-2,0) node (n2) [left] {RF};
\draw (C) -| ++(0,-1)-| ++(-2.5,0) node (n2) [left] {SVM};

\end{tikzpicture}
\end{document}
share|improve this question
    
What have you tried so far? Please provide with a full example (including \documentclass{article} etc.) –  zeroth Aug 14 at 12:53
    
Search the pgf manual for -| and |-, the vertical/horizontal (and vice-versa) line operations. –  Paul Gessler Aug 14 at 12:55
1  
I'll provide current code as soon as possible. –  Andrej Aug 14 at 12:56
    
I'm perplexed. Why is this a "rug plot"? –  Andrew Aug 14 at 13:13
    
@Andrew: please suggest the right name. –  Andrej Aug 14 at 13:16

1 Answer 1

up vote 5 down vote accepted

Here is a quick and dirty solution for your problem. All the information you need can also be taken easily from the pgfmanual as stated above.

The solution is based on using coordinates for the interesting points. This way the code can be reused easily with other values.

\documentclass[border=5mm, tikz]{standalone}
\usepackage{xifthen}
\usetikzlibrary{calc, positioning}

\begin{document}
\begin{tikzpicture}
\tikzset{
  lbl/.style={
    text width=1.5cm,
  },
 }
 % axis
 \draw (1,0) -- (4,0);
 \foreach \x [count=\i] in {1,...,4} {
  \draw (\x, 0) -- ++(0,.1) node [above] {\i};
  \ifthenelse{\x < 4}{\draw (\x+.5, 0) -- ++(0,.05);}{}
 }

 % coordinates
 \coordinate (c0) at (1,0);
 \coordinate (c1) at (1.8,0);
 \coordinate (c2) at (2.75,0);
 \coordinate (c3) at (3.2,0);
 \coordinate (c4) at (3.3,0);
 \coordinate (c5) at (4,0);

 % cd
 \draw [|-|] ($(c0) +(0,.75)$) -- ($(c1) +(0,.75)$) node [midway, above] {CD};

 % labels
 \node (l1) at (c0) [below left=.25cm and 0cm, lbl, align=right] {first};
 \node (l2) [below=0cm of l1, lbl, align=right] {second};
 \node (l4) at (c5) [below right=.25cm and 0cm, lbl, align=left] {fourth};
 \node (l3) [below=0cm of l4, lbl,  align=left] {third};

 % connectors
 \foreach \x in {1,...,4} {
  \draw (l\x) -| (c\x);
 };
 \draw [ultra thick] ($(c2)+(-.1,-.25)$) -- ($(c4)+(.1,-.25)$);

\end{tikzpicture}
\end{document}

Rendered image

share|improve this answer

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.