pgf-tikz / pgfplots

pgfplots - A TeX package to draw normal and/or logarithmic plots directly in TeX in two and three dimensions with a user-friendly interface and pgfplotstable - a TeX package to round and format numerical tables. Examples in manuals and/or on web site.
http://pgfplots.sourceforge.net/
199 stars 33 forks source link

'set layers' has unwanted side effects #199

Open pgf-tikz-bot opened 6 years ago

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/199/ Author: flomile Timestamp: 2017-12-22 20:25:48.869000

The key set layers has some undesirable side effects:

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}
pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/199/#881d Author: cfeuersaenger Timestamp: 2017-12-23 11:38:18.374000

related, but no duplicate: https://sourceforge.net/p/pgfplots/bugs/153/

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/199/#6848 Author: cfeuersaenger Timestamp: 2017-12-23 12:32:48.263000

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}.

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/199/#bf2b Author: cfeuersaenger Timestamp: 2017-12-23 12:37:51.369000

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.

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/199/#3ea8 Author: flomile Timestamp: 2017-12-25 08:23:44.566000

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

pgf-tikz-bot commented 6 years ago

Migrated from SourceForge https://sourceforge.net/p/pgfplots/bugs/199/#f1ee Author: mo-gul Timestamp: 2018-08-06 12:35:59.237000

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