tikz add tag
Dr. Manuel Kuehner
 - This is a cross-post (see https://tex.stackexchange.com/questions/571816)!
 - A user in the chat recommended to ask here since some of the top `pgfplots` experts migrated here.
 - I got an answer on tex.stackexchange.com but I hope that there is a "better way".
 - I want to draw a diagram as shown in the hand drawing.
 - The idea is to provide a table with `x`, `y`, `color` and a `label` for each rectangle.

## Input ##
The input could look similar to the following. These are just generic proposals.

**Version 1 (Absolute Values)**

    x    y    color    label
    % First Column
    10   5    green    Labelx1y1
    10   15   green    Labelx1y2
    10   20   green    Labelx1y3
    % Second Column
    18   5    green    Labelx2y1
    18   15   green    Labelx2y2
    18   20   green    Labelx2y3
    % Third Column
    25   5    green    Labelx3y1
    25   15   green    Labelx3y2
    25   20   red      Labelx3y3 % RED rectangle

**Version 1 (Relative Values)**

In this example, the `x`-values and `y`-values are added.

    x    y    color    label
    % First Column
    10   5    green    Labelx1y1
    10   10   green    Labelx1y2
    10   5    green    Labelx1y3
    % Second Column
    8   5    green    Labelx2y1
    8   10   green    Labelx2y2
    8   5    green    Labelx2y3
    % Third Column
    7   5    green    Labelx3y1
    7   10   green    Labelx3y2
    7   5    red      Labelx3y3 % RED rectangle

## Output ##
[![enter image description here][2]][2]

## Main Question and Remarks ##

 - **Question:** Does this diagram type has a name?
 - **Main Question:** What would be a clever way to achieve this? 
 - **Remark:** I would prefer to use `pgfplots`.
 - **Remark:** I am not married to a specific input format - I generate the data myself (Matlab, Python, Excel) and can therefore influence it. 

  [1]: https://tex.stackexchange.com/questions/571629
  [2]: https://i.stack.imgur.com/KJ9QW.jpg
Top Answer
marmot
You already have answers using a patch plot and using a loop over a table. Here is a third option using a `scatter plot`. Note that many plot types are secretly scatter plots. In fact, this code is an adaptation of some answer on TeX.SE which served a slightly different purpose. Let me first mention a downside of the current implementation: you need to set `xmax` and `ymax` by hand. This can be avoided by letting LaTeX find these values, but since you generate the data automatically you may also let your code this. In case this is needed, I will be happy to add this to the answer. 

Next, let us disect the code. With `clip mode=individual,` we turn on individual clipping, you can turn this off in the current version or for testing. More importantly, with
```
  	visualization depends on={value \thisrow{xmin} \as \myxmin},
	visualization depends on={value \thisrow{xmax} \as \myxmax},
	visualization depends on={value \thisrow{ymin} \as \myymin},
	visualization depends on={value \thisrow{ymax} \as \myymax},
	visualization depends on={value \thisrow{color} \as \mycolor},
	visualization depends on={value \thisrow{label} \as \mylabel},
```
we make the entries of the current row available to the scatter code. The scatter code is
```
scatter/@pre marker code/.append code={
            \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
            \path[draw=black,fill=\mycolor] 
             (axis direction cs:0,0) rectangle 
			 (axis direction cs:\myxmax-\myxmin,\myymax-\myymin);
			\path  (axis direction cs:0.5*\myxmax-0.5*\myxmin,0)
			 node[above]{\mylabel};
            \pgfplotsset{mark=none}
```
It contains Ti*k*Z directives that make use of the macros that we got out of the table entries. 

And here are the current version of the complete code and the result.

```
\begin{filecontents}[overwrite]{patches.txt}
xmin ymin xmax  ymax  color    label
% First Column
0  0 10   5    green    Labelx1y1
0  5 10   15   green    Labelx1y2
0  15 10   20   green    Labelx1y3
% Second Column
10 0 18   5    green    Labelx2y1
10 5 18   15   green    Labelx2y2
10 15 18   20   green    Labelx2y3
% Third Column
18 0 25   5    green    Labelx3y1
18 5 25   15   green    Labelx3y2
18 15 25   20   red      Labelx3y3
\end{filecontents}
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[width=10cm,xmax=27.5,ymax=22.5]
  \addplot[scatter,only marks,
    clip mode=individual,
  	visualization depends on={value \thisrow{xmin} \as \myxmin},
	visualization depends on={value \thisrow{xmax} \as \myxmax},
	visualization depends on={value \thisrow{ymin} \as \myymin},
	visualization depends on={value \thisrow{ymax} \as \myymax},
	visualization depends on={value \thisrow{color} \as \mycolor},
	visualization depends on={value \thisrow{label} \as \mylabel},
	scatter/@pre marker code/.append code={
            \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
            \path[draw=black,fill=\mycolor] 
             (axis direction cs:0,0) rectangle 
			 (axis direction cs:\myxmax-\myxmin,\myymax-\myymin);
			\path  (axis direction cs:0.5*\myxmax-0.5*\myxmin,0)
			 node[above]{\mylabel};
            \pgfplotsset{mark=none}
        },
	] table {patches.txt};	
 \end{axis}
\end{tikzpicture}
\end{document}
```

![Screen Shot 2020-11-22 at 7.33.47 PM.png](/image?hash=d4b2d10e7655a762e53a2d0db09926f28fb369f8d43a37e20a3d7d6526b9b4c6)

And here is a code that gets `xmax` and `ymax` from the table.
```
\begin{filecontents}[overwrite]{patches.txt}
xmin ymin xmax  ymax  color    label
% First Column
0  0 10   5    green    Labelx1y1
0  5 10   15   green    Labelx1y2
0  15 10   20   green    Labelx1y3
% Second Column
10 0 18   5    green    Labelx2y1
10 5 18   15   green    Labelx2y2
10 15 18   20   green    Labelx2y3
% Third Column
18 0 25   5    green    Labelx3y1
18 5 25   15   green    Labelx3y2
18 15 25   20   red      Labelx3y3
\end{filecontents}
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
 \pgfplotstableread{patches.txt}\dataA
 \pgfmathsetmacro{\currentxmax}{-16000}%
 \pgfplotstableforeachcolumnelement{xmax}\of\dataA\as\myx{%
 	\pgfmathsetmacro{\currentxmax}{max(\currentxmax,\myx)}}
 \pgfmathsetmacro{\currentymax}{-16000}%
 \pgfplotstableforeachcolumnelement{ymax}\of\dataA\as\myy{%
 	\pgfmathsetmacro{\currentymax}{max(\currentymax,\myy)}}	
 \begin{axis}[width=10cm,xmax=1.1*\currentxmax,ymax=1.1*\currentymax]
  \addplot[scatter,only marks,
    clip mode=individual,
  	visualization depends on={value \thisrow{xmin} \as \myxmin},
	visualization depends on={value \thisrow{xmax} \as \myxmax},
	visualization depends on={value \thisrow{ymin} \as \myymin},
	visualization depends on={value \thisrow{ymax} \as \myymax},
	visualization depends on={value \thisrow{color} \as \mycolor},
	visualization depends on={value \thisrow{label} \as \mylabel},
	scatter/@pre marker code/.append code={
            \pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}
            %\pgfmathsetmacro\negheight{-1*\myx}         
            \path[draw=black,ultra thick,fill=\mycolor] 
             (axis direction cs:0,0) rectangle 
			 (axis direction cs:\myxmax-\myxmin,\myymax-\myymin);
			%\path (axis cs:\myxmax,\myymax);
			\path  (axis direction cs:0.5*\myxmax-0.5*\myxmin,0)
			 node[above]{\mylabel};
            \pgfplotsset{mark=none}
        },
	] table {patches.txt};	
 \end{axis}
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-11-22 at 8.36.54 PM.png](/image?hash=75d918a533e3f701f46a454eb5b60097bca312c3f8545256844a3ca5d2e29354)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.