3

How would it be possible to achieve something like the following I attach with TikZ and further to be able to color differently and even put a legend inside each smaller shape?

wanted

  • 1
    Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – yo' Jan 25 '15 at 18:44
  • If you'd provide us with a MWE and an explication of what exactly it is you're struggling with it will be easier for people to set you on the right path. A few hints: (1) drawing an axis goes like \draw[->] (0,0) -- (8,0); (2) drawing a line goes like \draw (0,0) -- (8,8); (3) drawing a (filled) polygon goes like \draw[fill=gray] (4.5,2.5) -- (4.5,4.5) -- (6.5,6.5) -- (6.5,2.5) -- cycle; – Maarten Dhondt Jan 25 '15 at 19:34

1 Answers1

4

This is an easy job for the fillbetween library from pgfplots. A simple example:

enter image description here

The code:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  xmin=100,
  xmax=800,
  ymin=0,
  ymax=600,
  domain=100:800
]
% The main line (the graph of the function)
\addplot+[no marks,black,name path=main line] {0.857*x-85};
% The x axis
\addplot+[no marks,black,name path=xaxis] {0};
% The vertical lines
\draw 
  (axis cs:350,0) -- (axis cs:350,0.857*350-85);
\draw 
  (axis cs:450,0) -- (axis cs:450,0.857*450-85);
\draw 
  (axis cs:650,0) -- (axis cs:650,0.857*650-85);
% The horizontal lines
\draw[name path=hline1] 
  (axis cs:450,250) -- (axis cs:800,250);
\draw[name path=hline2] 
  (axis cs:650,450) -- (axis cs:800,450) coordinate (aux7);
% Filling the regions
\addplot[orange!30] 
  fill between[of=main line and xaxis,soft clip={domain=100:350}];
\addplot[green!80!black!50] 
  fill between[of=main line and xaxis,soft clip={domain=350:450}];
\addplot[magenta!50] 
  fill between[of=main line and hline1,soft clip={domain=450:650}];
\addplot[olive!50] 
  fill between[of=hline1 and xaxis,soft clip={domain=450:650}];
\addplot[cyan!50] 
  fill between[of=main line and hline2,soft clip={domain=650:800}];
\addplot[yellow!50] 
  fill between[of=hline2 and hline1,soft clip={domain=650:800}];
\addplot[red!80!black] 
  fill between[of=hline1 and xaxis,soft clip={domain=650:800}];
\end{axis} 
\end{tikzpicture}

\end{document}
Gonzalo Medina
  • 505,128