以下 MWE:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.8}
\begin{filecontents}{depensezero.dat}
2010,14.0,67.0,19.0
2011,33.0,39.0,28.0
2012,64.0,12.0,24.0
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xbar stacked, ytick=data, symbolic y coords = {2012, 2011, 2010}]
\addplot[fill=blue] table [y index=0, x index=1, meta index=1, col sep = comma] {depensezero.dat};
\addplot[fill=orange] table [y index=0, x index=2, meta index=2, col sep = comma] {depensezero.dat};
\addplot[fill=yellow] table [y index=0, x index=3, meta index=3, col sep = comma] {depensezero.dat};
\node at (axis cs:0,2010) (src) {};
\node at (axis cs:0,2011) (dest) {};
\end{axis}
\draw[->, >=latex, draw=red, red, thick, bend right=90] (src.west) to node[left, text=red] {+12\%} (dest.west);
\end{tikzpicture}
\end{document}
在图形的两个 y 刻度之间生成一个箭头。我想修改这个箭头使它代表一个完整的半圆,即箭头应该向西稍微一点。
答案1
您可以根据需要添加distance=<length>
以使其更远:
代码:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.8}
\begin{filecontents}{depensezero.dat}
2010,14.0,67.0,19.0
2011,33.0,39.0,28.0
2012,64.0,12.0,24.0
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xbar stacked, ytick=data, symbolic y coords = {2012, 2011, 2010}]
\addplot[fill=blue] table [y index=0, x index=1, meta index=1, col sep = comma] {depensezero.dat};
\addplot[fill=orange] table [y index=0, x index=2, meta index=2, col sep = comma] {depensezero.dat};
\addplot[fill=yellow] table [y index=0, x index=3, meta index=3, col sep = comma] {depensezero.dat};
\node at (axis cs:0,2010) (src) {};
\node at (axis cs:0,2011) (dest) {};
\end{axis}
\draw[->, >=latex, draw=red, red, thick, bend right=90, distance=2cm] (src.west) to node[left, text=red] {+12\%} (dest.west);
\end{tikzpicture}
\end{document}
答案2
您还可以使用controls
:
\draw[->, >=latex, draw=red, red, thick,controls=+(180:2) and +(180:2)] (src.west) to
node[left, text=red] {+12\%} (dest.west);
这样你就可以改变角度和距离。
\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\pgfplotsset{compat=1.8}
\begin{filecontents}{depensezero.dat}
2010,14.0,67.0,19.0
2011,33.0,39.0,28.0
2012,64.0,12.0,24.0
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xbar stacked, ytick=data, symbolic y coords = {2012, 2011, 2010}]
\addplot[fill=blue] table [y index=0, x index=1, meta index=1, col sep = comma] {depensezero.dat};
\addplot[fill=orange] table [y index=0, x index=2, meta index=2, col sep = comma] {depensezero.dat};
\addplot[fill=yellow] table [y index=0, x index=3, meta index=3, col sep = comma] {depensezero.dat};
\node[anchor=east] at (axis cs:0,2010) (src) {\phantom{2010}};
\node[anchor=east] at (axis cs:0,2011) (dest) {\phantom{2011}};
\end{axis}
\draw[->, >=latex, draw=red, red, thick] (src.west) to[controls=+(180:2) and +(180:2)] node[left, text=red] {+12\%} (dest.west);
\end{tikzpicture}
\end{document}