'set layers' has unwanted side effects
Brought to you by:
cfeuersaenger,
ludewich
The key set layers has some undesirable side effects:
butt as can be seen at the origin.The reason I am using set layers in the MWE below is that I wanted to draw filled areas touching the axes without hiding them.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{center}
\begin{tikzpicture}[line cap=rect]
\begin{axis}[axis x line=bottom, axis y line=left, thick,
xmin=0, xmax=1, ymin=0, ymax=1, xtick=\empty, ytick=\empty]
\end{axis}
\begin{axis}[axis x line=bottom, axis y line=left, thick,
xmin=0, xmax=1, ymin=0, ymax=1, xtick=\empty, ytick=\empty,
xshift=8cm, set layers=standard,]
\addplot [on layer=axis background, fill=black!10, draw=none]
coordinates {(0,0) (0.5,0) (0.5,0.5) (0,0.5)};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
related, but no duplicate: https://sourceforge.net/p/pgfplots/bugs/153/
Thanks for the bug report. You are right: the layer code fails to apply the bounding box.
The root cause is that a sub-component (
cell picture=false) which is normally necessary forset layershas a defect when it comes to transformations. In your case,xshift=8cmis not applied to the bounding box.I will look into the issue, but it is difficult and might take some time ... even more time than the next release.
Fortunately, you may be able to work around the problem. Here are two unrelated suggestions:
the defect is in the implementation of
cell picture=falsewhich is implicitly activated whenever you writeset layers. However,cell picture=falseis only required for multiple axes sharing these layers in the same picture. In your case, it is unnnecessary! Thus, you can addcell picture=trueright afterset layersand it will work.If you experience issues with (1), you can write a separate tikzpicture for every axis, and to move the transformations right after
\begin{tikzpicture}.Last edit: Stefan Pinnow 2018-08-06
The problem with
thicknot being applied as soon as you write layers is not addressed, though.I believe this is another defect: apparently, I need to apply such styles to every layer in question... not only the main layer.
If you define the style for the graphics elements in question like
axis line style={ultra thick},it appears to work...
I will think about a solution.
Last edit: Stefan Pinnow 2018-08-06
Thanks for your suggestions! Indeed,
axis line style={thick, line cap=rect}, cell picture=truefixes all issues I had.For the record: This bug also shows up in TeX.SX question https://tex.stackexchange.com/q/444645/95441