TikZ: rotating scope changes the shading, but not how you'd expect

It is my understanding that the shading in the following code is applied after the scope transformation.

\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}
\begin{document}
color(0cm)=(red);
color(.3cm)=(orange);
color(.6cm)=(yellow);
color(.9cm)=(green);
color(1.2cm)=(blue);
color(1.5cm)=(purple);
color(1.8cm)=(brown)
}

\begin{tikzpicture}
\begin{scope}[rotate=26.73]
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}
\end{scope}
\end{tikzpicture}

\end{document}


Given that a circle is symmetrical by rotation, the result of both tikzpictures should be the same. Yet the shading is different. Why is this the case?

• The shading is done on the basis of the bounding box. A circle is constructed from Bezier curves, and this means that its bounding box changes under rotations. As you can see, the circles are not vertically aligned either, for the same reason. – user194703 Apr 17 '20 at 16:25
• – user108724 Apr 17 '20 at 16:30

The shading is done on the basis of the bounding box, see e.g. here. A circle is constructed from Bezier curves, and this means that its bounding box changes under rotations. As you can see, the circles are not vertically aligned either, for the same reason. Once you fix the bounding box, the effect is gone.

\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{bbox}
\begin{document}
color(0cm)=(red);
color(.3cm)=(orange);
color(.6cm)=(yellow);
color(.9cm)=(green);
color(1.2cm)=(blue);
color(1.5cm)=(purple);
color(1.8cm)=(brown)
}

\begin{tikzpicture}[bezier bounding box]
\begin{scope}[rotate=26.73]
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}
\end{scope}
\end{tikzpicture}

\end{document}


If you want to rotate the shading, change the shading angle. (You can also use transform canvas but this is sometimes a bit hard to tame.)

\documentclass[varwidth,margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{bbox}
\begin{document}
color(0cm)=(red);
color(.3cm)=(orange);
color(.6cm)=(yellow);
color(.9cm)=(green);
color(1.2cm)=(blue);
color(1.5cm)=(purple);
color(1.8cm)=(brown)
}

\begin{tikzpicture}[bezier bounding box]
\begin{scope}[transform canvas={rotate=26.73}]
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}[bezier bounding box]
\begin{scope}

• Can bezier bounding box be used with a scope, or does it have to apply to the entire tikzpicture? – usernumber Apr 17 '20 at 19:58
• Note that the bbox library was removed from TikZ with version 3.1.6 due to licensing issues: github.com/pgf-tikz/pgf/releases/tag/3.1.6 – Torbjørn T. Sep 28 '20 at 18:25