3

I produce the following chart:

enter image description here

With this code:

\documentclass[border=5pt]{standalone}

% colors \usepackage[table]{xcolor} \definecolor{c1}{HTML}{122084} \definecolor{c2}{HTML}{4e7eba} \definecolor{c3}{HTML}{81a4c9} \definecolor{c4}{HTML}{b3c9d8} \definecolor{c5}{HTML}{d8d9d9} \definecolor{c6}{HTML}{ff8091} \definecolor{c6d}{HTML}{db4d60}

% tikz-related \usepackage{tikz} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepgfplotslibrary{dateplot} \pgfplotsset{compat=1.17}

% math \usepackage{amsmath} \usepackage{amssymb}

\begin{document}

\begin{tikzpicture}

\pgfplotstableread[col sep=comma]{ type, agri, mng, mfg, cons, fin, nonfin FDI, 0.8, 0.7, 0.6, 0.5, 0.3, 0.3 DIA, 0.8, 0.7, 0.6, 0.5, 0.3, 0.3 }\chart

\begin{axis}[ybar stacked, font = \footnotesize, width = 8.5cm, height = 6cm, bar width=18mm, axis lines=left, enlarge x limits=0.5, % % y ticks style and label ylabel={RM billion}, ymin = 0.01, ymax = 3.4, ylabel shift = 1pt, ytick distance = 0.5, y tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1, /tikz/.cd}, % % x axis ticks and style xtick=data, xticklabels from table={\chart}{type},
table/x expr = \coordindex, ] % % done with the axis, now the plots \addplot [ybar stacked, c1, fill] table [y=agri] {\chart}; \addplot [ybar stacked, c2, fill] table [y=mng] {\chart}; \addplot [ybar stacked, c3, fill] table [y=mfg] {\chart}; \addplot [ybar stacked, c4, fill] table [y=cons] {\chart}; \addplot [ybar stacked, c5, fill] table [y=fin] {\chart}; \addplot [ybar stacked, c6, fill] table [y=nonfin] {\chart}; \end{axis} \node[text width = 8.2cm, align = left] at (3.3,-1.2){\footnotesize Note: For DIA, positive (negative) values are net \newline outflows (inflows). Figures may not add up due to rounding.}; \end{tikzpicture}

\end{document}

Right now, the 'Note' at the bottom of the picture has been manually placed with:

\node[text width = 8.2cm, align = left] at (3.3,-1.2){\footnotesize Note: ...};

How can I automatically place it at the bottom left corner?

Thev
  • 1,568

1 Answers1

6

Pgfplots defines (4.19 Alignment Options) a node which is that of the axes called current axis. It suffices to position on the below south west anchor of current axis: (current axis.below south west).

\node[text width = 8.2cm, align = left,anchor=north west] 
at (current axis.below south west){...};

I quote the pgfplots manual:

enter image description here

enter image description here


Thus, the full code is :

screenshot

\documentclass[border=5pt]{standalone}

% colors \usepackage[table]{xcolor} \definecolor{c1}{HTML}{122084} \definecolor{c2}{HTML}{4e7eba} \definecolor{c3}{HTML}{81a4c9} \definecolor{c4}{HTML}{b3c9d8} \definecolor{c5}{HTML}{d8d9d9} \definecolor{c6}{HTML}{ff8091} \definecolor{c6d}{HTML}{db4d60}

% tikz-related \usepackage{tikz} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepgfplotslibrary{dateplot} \pgfplotsset{compat=1.17}

% math \usepackage{amsmath} \usepackage{amssymb}

\begin{document}

\begin{tikzpicture}

\pgfplotstableread[col sep=comma]{ type, agri, mng, mfg, cons, fin, nonfin FDI, 0.8, 0.7, 0.6, 0.5, 0.3, 0.3 DIA, 0.8, 0.7, 0.6, 0.5, 0.3, 0.3 }\chart

\begin{axis}[ybar stacked, font = \footnotesize, width = 8.5cm, height = 6cm, bar width=18mm, axis lines=left, enlarge x limits=0.5, % % y ticks style and label ylabel={RM billion}, ymin = 0.01, ymax = 3.4, ylabel shift = 1pt, ytick distance = 0.5, y tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1, /tikz/.cd}, % % x axis ticks and style xtick=data, xticklabels from table={\chart}{type},
table/x expr = \coordindex, ] % % done with the axis, now the plots \addplot [ybar stacked, c1, fill] table [y=agri] {\chart}; \addplot [ybar stacked, c2, fill] table [y=mng] {\chart}; \addplot [ybar stacked, c3, fill] table [y=mfg] {\chart}; \addplot [ybar stacked, c4, fill] table [y=cons] {\chart}; \addplot [ybar stacked, c5, fill] table [y=fin] {\chart}; \addplot [ybar stacked, c6, fill] table [y=nonfin] {\chart}; \end{axis}

\node[text width = 8.2cm, align = left,anchor=north west] at (current axis.below south west){\footnotesize Note: For DIA, positive (negative) values are net \newline outflows (inflows). Figures may not add up due to rounding.}; \end{tikzpicture}

\end{document}

AndréC
  • 24,137