3

I create my diagram with the following code.

\documentclass{article}
%
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols,patterns}
%
\pagestyle{empty}
%
\begin{document}
%
\tikzset{
bar cross/.style={rectangle, pattern=north east lines, minimum height=50mm, minimum width=10mm, draw=black, 
                  anchor=north},
bar/.style={rectangle, minimum height=50mm, minimum width=10mm, draw=black,anchor=north}
}
%
\begin{tikzpicture}
  \node(01)[bar,minimum height=30mm]at(0.0,0){};
  \node[above]at(01.north){$m_1$};
  \node(011)[bar cross,minimum height=20mm]at(0.0,-3){};

  \node(02)[bar,minimum height=5mm]at(1.5,0){};
  \node[above]at(02.north){$m_1$};
  \node(021)[bar cross,minimum height=10mm]at(1.5,-0.5){};
  \node(022)[bar,minimum height=5mm]at(1.5,-1.5){};
  \node(023)[bar cross,minimum height=15mm]at(1.5,-2.0){};
  \node(024)[bar,minimum height=15mm]at(1.5,-3.5){};

  \node(03)[bar cross,minimum height=2.5mm]at(3.0,0){};
  \node[above]at(03.north){$m_3$};
  \node(031)[bar,minimum height=25mm]at(3.0,-0.25){};
  \node(031)[bar cross,minimum height=22.5mm]at(3.0,-2.75){};

  \node(04)[bar,minimum height=32mm]at(4.5,0){};
  \node[above]at(04.north){$m_4$};
  \node(041)[bar cross,minimum height=2.5mm]at(4.5,-3.2){};
  \node(042)[bar,minimum height=15.5mm]at(4.5,-3.45){};

  \node(05)[bar cross,minimum height=10mm]at(6.0,0){};
  \node[above]at(05.north){$m_5$};
  \node(055)[bar,minimum height=40mm]at(6.0,-1){};

  \node(beob)[bar,minimum height=5mm]at(7.5,-2.5){};
  \node[right]at(beob.east){type 1};

  \node(fehl)[bar cross,minimum height=5mm]at(7.5,-3.5){};
  \node[right]at(fehl.east){type 2};

  \draw[->](-5,-5) -- (2.5,-2.75);
\end{tikzpicture}
%
\end{document}
%

I think, that lines where rectangles overlap seem to me very thick, is this right or only my opinion? The arrow shows such a line.

The second question is, how can I improve my diagram, I'm tikz beginner and I think the code could be improved.

  • I guess that you can use pgfplots to produce bars graphs. – Sigur Nov 18 '13 at 21:44
  • Do you want only the horizontal line splitting the areas? If you want to change the whole rectangle use line width=1pt inside its style. – Sigur Nov 18 '13 at 21:45
3

Consider this as a showcase which is admittedly a little too much if you are not familiar with pgfplots. But just providing stacked bar plot coordinates you can let it build the graph for you (I just eyeballed the coordinates quickly)

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usetikzlibrary{patterns}
%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
  ybar stacked,
  bar width=1cm,
  stacked ignores zero,
  ymin=0,xmin=0,
  ymax=6,xmax=6,
  enlargelimits=false,
  area legend,
  legend entries={Type 1,Type 2},
  legend style={at={(axis description cs:1.0,0.5)},anchor=west},
  axis lines=none,
]
\addplot[]                         coordinates {(1,0) (2,1.5) (3,0)   (4,1.5) (5,4)};
\addplot[pattern=north west lines] coordinates {(1,2) (2,1.5) (3,2.2) (4,0.2) (5,1)};
\addplot[]                         coordinates {(1,3) (2,0.5) (3,2.5) (4,3.3) (5,0)};
\addplot[pattern=north west lines] coordinates {(1,0) (2,1)   (3,0.3) (4,0)   (5,0)};
\addplot[]                         coordinates {(1,0) (2,0.5) (3,0)   (4,0)   (5,0)};

\pgfplotsinvokeforeach{1,...,5}{
\node[above] (a#1) at (axis cs:#1,5){$m_#1$};
}
\end{axis}
\end{tikzpicture}
\end{document}

There are many other details that can be incorporated but I don't want to obfuscate the main idea.

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.