# Fitting a tikz graph to a ZY plane canvas

I learned how to draw things in the ZY plane, but I didn't fully understand how it works. Below is my code:

\documentclass{standalone}

\usepackage{tikzducks}
\usetikzlibrary{3d,graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

\begin{tikzpicture}
\newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\graphA}{\graph [nodes={circle, inner sep=0pt, minimum size=2mm, fill, as=}]{
a -- { b -- c -- { d -- e, f -- { g, h }}, i -- j -- k[second] }
};}
\begin{scope}[canvas is zy plane at x=0]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=0.8]
\planes
\duck
\end{scope}
\begin{scope}[canvas is zy plane at x=1.6]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=2.4]
\planes
\graphA
\end{scope}
\end{tikzpicture}

\end{document}

The output:

The tikz duck can fit in the ZY plane canvas automatically, but my customized graph cannot. Why would it be like this? How to fit the graph to the ZY plane canvas?

Since what you are drawing are nodes, they escape by default from transforming their figures since only their positions are affected, so if they do so you must indicate the transform shape modifier, which as you can see also affects the nodes. Here are some examples with some arrangements so that they can be read.

RESULT:

MWE:

%Compiled using LuaLatex, needeed for graphs,graphdrawing
\documentclass[border=3.14pt]{standalone}
\usepackage{tikzducks}
\usetikzlibrary{3d,graphs,graphdrawing}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}
\newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\graphA}{\graph[nodes={circle, inner sep=0pt, minimum size=2mm, fill}]{
a -- { b -- c -- { d -- e, f -- { g, h }}, i -- j -- k }
};}
\begin{scope}[canvas is zy plane at x=0]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=0.8]
\planes
\duck
\end{scope}
\begin{scope}[canvas is zy plane at x=1.6]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=2.4, transform shape]
\planes
\begin{scope}[yshift=2cm,scale=0.5]
\graphA
\end{scope}

\end{scope}
\begin{scope}[canvas is zy plane at x=3.2]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=4]
\planes
\draw[](1,1) node[label=90:default] {\includegraphics[height=1cm]{example-image-a}};
\end{scope}
\begin{scope}[canvas is zy plane at x=4.8]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=5.6,transform shape]
\planes
\draw[](1,1) node[label=transform shape]{\includegraphics[height=1cm]{example-image-b}};
\end{scope}
\begin{scope}[canvas is zy plane at x=6.4]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=7.7,transform shape]
\planes
\draw[](1,1) node[label={[xscale=-1]90:xscale=-1},xscale=-1]{\includegraphics[height=1cm]{example-image-c}};
\end{scope}

\end{tikzpicture}

\end{document}

Seems that the default graph layout caused the issue, I added binary tree layout to the graph option which solved the issue. I futher wrapped the graph within a scope environment to rescale and move it to the center of the gray plane by setting scale, xshift and yshift:

\documentclass{standalone}

\usepackage{tikzducks}
\usetikzlibrary{3d,graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

\begin{tikzpicture}
\newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
\newcommand{\graphA}{
\begin{scope}[scale=0.4,xshift=40,yshift=20]{
\graph[binary tree layout, nodes={circle, inner sep=0pt, minimum size=2mm, fill, as=}, grow=up]{
a -- { b -- c -- { d -- e, f -- { g, h }}, i -- j -- k[second] }
};
}
\end{scope}
}
\begin{scope}[canvas is zy plane at x=0]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=0.8]
\planes
\duck
\end{scope}
\begin{scope}[canvas is zy plane at x=1.6]
\hooks
\end{scope}
\begin{scope}[canvas is zy plane at x=2.4]
\planes
\graphA
\end{scope}
\end{tikzpicture}

\end{document}

The output: