I have a stacked area chart where several areas have just about 1-2 mm height.
What I'm now planning to do is the following:
- remove the legend
- where there is enough space for it add the series label directly in the chart
- where there is not enough space for it add a black line pointing to the origin area in the chart and at the other end of the line print the series label
Is this possible with pgfplots?
My LaTeX code looks like this:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepackage{filecontents}
\pgfplotsset{
compat=newest,
every x tick label/.append style={rotate=45,anchor=east,yshift=-0.3cm},
axis lines*=left,
table/col sep=semicolon,
}
\begin{document}
\definecolor{gray1}{HTML}{828d94}
\definecolor{gray2}{HTML}{9ea6ab}
\definecolor{gray3}{HTML}{b9bfc3}
\definecolor{gray4}{HTML}{d4d8db}
\definecolor{bronze1}{HTML}{bab194}
\definecolor{bronze2}{HTML}{cec7b3}
\definecolor{bronze3}{HTML}{e2ded2}
\definecolor{bronze4}{HTML}{f6f5f1}
\definecolor{green1}{HTML}{94bab1}
\definecolor{green2}{HTML}{b3cec7}
\definecolor{green3}{HTML}{d2e2de}
\definecolor{green4}{HTML}{f1f6f5}
\begin{filecontents}{sample.csv}
Metrik Nr;Small A;Small B;Small C;Small D;Mid A;Mid B;Mid C;Mid D;Big A;Big B;Big C;Big D;Gesamt;Small A Prozent;Small B Prozent;Small C Prozent;Small D Prozent;Mid A Prozent;Mid B Prozent;Mid C Prozent;Mid D Prozent;Big A Prozent;Big B Prozent;Big C Prozent;Big D Prozent
1;20.0;0.5;0.5;2.0;0.5;0.5;0.5;0.5;20.0;5.0;5.0;2.0;57;35.0877193;0.877192982;0.877192982;3.50877193;0.877192982;0.877192982;0.877192982;0.877192982;35.0877193;8.771929825;8.771929825;3.50877193
2;10.0;0.5;0.5;0.5;0.5;0.5;0.5;0.5;12.0;20.0;8.0;0.5;54;18.51851852;0.925925926;0.925925926;0.925925926;0.925925926;0.925925926;0.925925926;0.925925926;22.22222222;37.03703704;14.81481481;0.925925926
3;7.00;2.00;2.00;2.00;1.00;1.00;1.00;1.00;20.00;10.00;10.00;2.00;59;11.86440678;3.389830508;3.389830508;3.389830508;1.694915254;1.694915254;1.694915254;1.694915254;33.89830508;16.94915254;16.94915254;3.389830508
\end{filecontents}
\begin{tikzpicture}[]
\begin{axis}[
height=0.85\textheight,
width=\textwidth,
xtick={1,2,3},
xticklabels={Metric 1, Metric 2, Metric 3},
yticklabel={\pgfmathparse{\tick}\pgfmathprintnumber{\pgfmathresult}\%},
ymin=0,
ymax=100,
stack plots=y,
area style,
scaled y ticks=false,
legend style={at={(0.5,-0.20)}, anchor=north,legend columns=4},
cycle list={
{gray1,fill=gray1,mark=none},
{gray2,fill=gray2,mark=none},
{gray3,fill=gray3,mark=none},
{gray4,fill=gray4,mark=none},
{bronze1,fill=bronze1,mark=none},
{bronze2,fill=bronze2,mark=none},
{bronze3,fill=bronze3,mark=none},
{bronze4,fill=bronze4,mark=none},
{green1,fill=green1,mark=none},
{green2,fill=green2,mark=none},
{green3,fill=green3,mark=none},
{green4,fill=green4,mark=none},
},
]
\addplot table [x=Metrik Nr,y=Small A Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Small B Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Small C Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Small D Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Mid A Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Mid B Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Mid C Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Mid D Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Big A Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Big B Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Big C Prozent] {sample.csv}
\closedcycle;
\addplot table [x=Metrik Nr,y=Big D Prozent] {sample.csv}
\closedcycle;
\legend{Small A, Small B, Small C, Small D,
Mid A, Mid B, Mid C, Mid D,
Big A, Big B, Big C, Big D}
\end{axis}
\end{tikzpicture}
\end{document}