Set outline first and fill colors later

Just use pic actions.

\documentclass[tikz,border=3.14mm]{standalone}

\begin{document}

\begin{tikzpicture}[scale=4, transform shape]
\tikzset{
    myc/.pic={
    \draw[line width=2mm,pic actions] (0, 0) -| (2, 1) -| (1, 2) -| (2, 3) -| cycle;
        }
}
\path (0,0) pic[fill=green] {myc} (1,3) pic[fill=blue] {myc} (2,6) pic[fill=blue] {myc};
\end{tikzpicture}

\end{document}

enter image description here


Your pic can have arguments.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}       
\pgfplotsset{compat=1.10,   
             ticks=none}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{backgrounds, 
                calc,
                patterns}

\begin{document}

\begin{tikzpicture}[scale=4, transform shape]
\tikzset{
    myc/.pic={
    \draw[line width=2mm,fill=#1] (0, 0) -| (2, 1) -| (1, 2) -| (2, 3) -| cycle;
        }
}
\path (0,0) pic {myc=red} (1,3) pic {myc=green} (2,6) pic {myc=blue};
\end{tikzpicture}

\end{document}

enter image description here

Tags:

Tikz Pgf