1

Is it possible to get a diagram like

enter image description here

-this is the output- (the whole rectangle has an area of "100%")

from fictional datas like

data name     color 
22   A        gray     
5    C        blue       
5    D        orange  

-this is the input-

MWE with wrong output:

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
]
\addplot[xtick=data,] table[y index=0] {
data name     color 
22    A          gray     
5      C          blue       
5      D         orange      
};
\end{axis}
\end{tikzpicture}
\end{document}
cis
  • 8,073
  • 1
  • 16
  • 45
  • Asking pdfplots for this sort of thing is a bit much, but with a bit of work you might be able to do it with tikz for a specific pattern of rectangles. – John Kormylo Jan 22 '20 at 19:31
  • @JohnKormylo Yes, the question is: Is there an automatism that plots a treemap from the table datas (seen above). To draw some connected rectangles with TikZ by myself is not a problem. – cis Jan 23 '20 at 07:33
  • There is a marimekko chart by Jake here: https://tex.stackexchange.com/a/62777 – Ross Jan 23 '20 at 15:20

2 Answers2

2

After installing pgf-pie I get a good square-pie.
But the package is not very flexible in some details.

enter image description here

\documentclass[border=5pt, tikz]{standalone}
\usepackage{pgf-pie}

\begin{document}
\begin{tikzpicture}[xscale = 1.75, 
 font=\sffamily,
mystyle/.style={draw=white, very thick, text=white, font=\sffamily\bfseries},
]
\pie[square,  
style={mystyle},
color={yellow!80!orange, gray, blue!40, orange}, 
%text=inside,
text=legend, 
]{68/A, 5/B, 5/C, 22/D}
\end {tikzpicture}

\end{document}
cis
  • 8,073
  • 1
  • 16
  • 45
1

enter image description here

A first attempt at pgfplots and rectangles adapted from -- https://tex.stackexchange.com/a/344816/197451

The MWE

    \documentclass[border=5pt]{standalone}
    \usepackage{pgfplots}
    \pgfplotsset{
    % use `compat' level 1.11 or higher so coordinates don't have to be
    % prefixed with `axis cs:' (any more)
    compat=1.11,
    }
    \begin{document}
    \begin{tikzpicture}[
    region/.style={
        draw=black!50,
        dashed,
    },
    Node/.style={
        midway,
        red,
    },
    declare function={
        xmin=0;
        xmax=12;
        ymin=0;
        ymax=300;
    },
    ]
    \begin{axis}[hide axis,
        xlabel={},
        ylabel={},
        xmin=xmin,
        xmax=xmax,
        ymin=ymin,
        ymax=ymax,
        axis background/.style={},
        extra x ticks={},
        extra y ticks={},
        title=title,
        ]
                    \draw [region,fill=brown!40] (xmin,ymin) rectangle (8,ymax)  node [Node, xshift=-55, yshift=-76] {68\%};

        \draw [region,fill=blue!40] (8,ymin)  rectangle (10,50)  node [Node, xshift=-10, yshift=-9] {5\%};
        \draw [region,fill=red!40] (10,ymin)   rectangle (xmax,50)  node [Node, xshift=-10, yshift=-9] {5\%};
        \draw [region,fill=gray!40] (8,50)   rectangle (xmax,ymax) node [Node, xshift=-24, yshift=-64] {22\%};

        \end{axis}
\end{tikzpicture}
\end{document}
js bibra
  • 21,280