# Draw two dependent figures with tikzpicture

For a report I want to create one figure showing the costs of employees vs. time in a small company. In the bottom figure the accumulated costs are shown.

The plots should look as follows:

With the following tex code I could achieve the following result:

% somewhere in the code
\definecolor{GR}{RGB}{60,170,70}

\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={
group size=1 by 2,
vertical sep=8pt,
x descriptions at=edge bottom},
xlabel={months},
domain=0:35,
width=\textwidth,height=0.7\textheight,
ymin = 0, ymax = 11,
xmajorgrids, %xtick=data, xticklabel interval boundaries
xtick={6,8,12,14,20,36}
]
\nextgroupplot[ylabel={}, yticklabels={,,}, ytick={\empty}]
\addplot[color=GR,mark=none,ultra thick] coordinates {(6,10) (36,10) (36,9) (6, 9) (6,10)};
\addplot[color=GR,mark=none,ultra thick] coordinates {(8,8) (36,8) (36,7) (8, 7) (8,8)};
\addplot[color=GR,mark=none,ultra thick] coordinates {(12,6) (36,6) (36,5) (12, 5) (12,6)};
\addplot[color=GR,mark=none,ultra thick] coordinates {(14,4) (36,4) (36,3) (14, 3) (14,4)};
\addplot[color=GR,mark=none,ultra thick] coordinates {(20,2) (36,2) (36,1) (20, 1) (20,2)};
\node at (axis cs:10,9.5){employee 1};
\node at (axis cs:14,7.5){employee 2};
\node at (axis cs:18,5.5){employee 3};
\node at (axis cs:22,3.5){employee 4};
\node at (axis cs:24,1.5){employee 5};

\nextgroupplot[
ylabel={loans},
height=0.3\textheight,ytick={3200,6400,9000,12200, 13200},
ymin = 0, ymax = 15000, ymajorgrids,
xmajorgrids, xtick=data, xticklabel interval boundaries
]
\addplot[color=GR,mark=none,ultra thick] coordinates {(6,3200) (8,3200) (8,6400) (12, 6400) (12,9000) (14, 9000) (14,12200) (20, 12200) (20, 13200) (36, 13200)};
\end{groupplot}
\end{tikzpicture}
\end{figure}


There are two problems left. The first is, that the labels (employees) should be on the left side and the x-axis labels should also be above the first plot as shown in the first image. The second problem is, that the values of the loans are scaled by 10^4 which is not intended.

• This is totally doable with pgfplots using a groupplot environment. – Vser Feb 10 '16 at 20:36
• @Vser thank you for your answer. I have edited my question (added some code) – blub Feb 10 '16 at 22:34
• To fix your second problem, use the key scaled ticks=false or something similar (I can't remember the exact key) – darthbith Feb 10 '16 at 22:42
• By the way, I'd rather go for the first graph with a bar graph. With the second answer to this question you see how to specify start and end value of the bar. You could then use symbolic x coords={E1,E2,E3,E4}, for each employee, you could then rotate your bar graph by setting anchor=origin, rotate around={<angle>:(current axis.origin)} and finally, for the second graph, if you'd put your data for the first graph in an array, you could sum your data using pgfplotstable to draw their sum. – Vser Feb 10 '16 at 23:27