I want to create a simple grouped stacked bar chart for 3 plots. Here is my code:
\documentclass[tikz,border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
every axis/.style={
ybar stacked,
legend pos=north west, ymin=0, ymax = 10,
bar width=3pt,
x tick label style={rotate=45,anchor=east}
}
]
\begin{axis}[bar shift=-9pt, legend style = {name = serieA}]
\addplot [fill=blue] coordinates {
(1,2)
(2,3)};
\addlegendentry{$a$}
\end{axis}
\begin{axis}[bar shift=-6pt, hide axis, legend style = {at = {([xshift=0.5mm, yshift = 2.9mm]serieA)}}]
\addplot [fill=orange] coordinates {
(1,4)
(2,5)};
\addlegendentry{$b$}
\end{axis}
\begin{axis}[bar shift=-3pt, hide axis, legend style = {at = {([xshift=10mm, yshift = 2.9mm]serieA)}}]
\addplot [fill=green] coordinates {
(1,6)
(2,7)};
\addlegendentry{$c$}
\end{axis}
\end{tikzpicture}
\end{document}
and the result is:
As you can see, there are three legends a, b, c which are separated from each other. I would like to have only one legend that includes all these three legends.


