Menu

#199 'set layers' has unwanted side effects

v1.0 (example)
open
nobody
None
5
2018-08-06
2017-12-22
Florian
No

The key set layers has some undesirable side effects:

  • TikZ does not recognize the size of the plot area anymore, e.g. the left-hand axis gets centered instead of the two axes together.
  • The axis lines are not drawn thick anymore.
  • The line cap is reset to 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}

Discussion

  • Christian Feuersänger

    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 for set layers has a defect when it comes to transformations. In your case, xshift=8cm is 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:

    1. the defect is in the implementation of cell picture=false which is implicitly activated whenever you write set layers. However, cell picture=false is only required for multiple axes sharing these layers in the same picture. In your case, it is unnnecessary! Thus, you can add cell picture=true right after set layers and it will work.

    2. 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
  • Christian Feuersänger

    The problem with thick not 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
  • Florian

    Florian - 2017-12-25

    Thanks for your suggestions! Indeed, axis line style={thick, line cap=rect}, cell picture=true fixes all issues I had.

     
  • Stefan Pinnow

    Stefan Pinnow - 2018-08-06

    For the record: This bug also shows up in TeX.SX question https://tex.stackexchange.com/q/444645/95441

     
MongoDB Logo MongoDB