summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/pgfplots/pgfplots.reference.closingplots.tex
blob: d201284ac15f9a7f24e696d86bba6fc3c8c00e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


\subsection{Closing Plots (Filling the Area Under Plots)}
\begin{command}{\closedcycle}
	Provide |\closedcycle| as \meta{trailing path commands} after |\addplot| to draw a closed line from the last plot coordinate to the first one.
	
	Use |\closedcycle| whenevery you intend to fill the area under a plot.

\begin{codeexample}[]
\begin{tikzpicture}
	\begin{axis}
	\addplot {x^2+2} \closedcycle;
	\end{axis}
\end{tikzpicture}
\end{codeexample}

\begin{codeexample}[]
\begin{tikzpicture}
	\begin{axis}
	\addplot+[fill] {x^2+2} \closedcycle;
	\end{axis}
\end{tikzpicture}
\end{codeexample}
	In case of stacked plots, |\closedcycle| connects the current plot with the previous plot instead of connecting with the $x$~axis\footnote{The implementation for stacked plots requires some additional logic to determine the filled area: \lstinline{\\closedcycle} will produce a \texttt{plot coordinates} command with \emph{reversed} coordinates of the previous plot. This is usually irrelevant for end users, but it assumes that the plot's type is symmetric. Since constant plots are inherently unsymmetric, \lstinline{\\closedcycle} will use \texttt{const plot mark right} as reversed sequence for \texttt{const plot mark left}.}.
\begin{codeexample}[]
\begin{tikzpicture}
	\begin{axis}[stack plots=y]
	\addplot+[fill] coordinates 
		{(0,1) (1,1) (2,2) (3,2)} \closedcycle;
	\addplot+[fill] coordinates 
		{(0,1) (1,1) (2,2) (3,2)} \closedcycle;
	\end{axis}
\end{tikzpicture}
\end{codeexample}
\end{command}