Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange interaction between "fill between", "transform shape" and label positioning. #375

Open
Rmano opened this issue Oct 12, 2020 · 3 comments

Comments

@Rmano
Copy link

Rmano commented Oct 12, 2020

Consider that code:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[
                scale=0.6, transform shape
                ]
                \begin{axis}[
                    width=6cm, height=6cm,
                    xmin=350, xmax=1100,
                    domain=300:1000, samples=100,
                    ymin=0, ymax=1,
                    axis x line = center,
                    axis y line = center,
                    enlarge x limits,
                    enlarge y limits,
                    xlabel = {$\lambda$~(\si{\nm})},
                    every axis x label/.append style = {at={(1.0, -0.2)}, },
                    ylabel = {$\xi_r$},
                    legend style = {nodes={right, font=\scriptsize}},
                    legend pos = north east,
                    clip mode = individual,
                    ]
                    \addplot [ultra thick, green!50!black, name path=A, domain=450:800] {exp(-(x-600)/400*(x-600)/100)};
                    \path [name path=B] (450,0) -- (800,0);
                    % \addplot [green] fill between [of=A and B];
            \end{axis}
\end{tikzpicture}
\end{document}

it gives the expected:

image

(Look at the x label position). If I uncomment the last line in the axis:

\addplot [green] fill between [of=A and B];

then the output is:

image

Notice how the labels moves.

This does not happen if I comment the scale=0.6, transform shape option.

@ilayn
Copy link
Member

ilayn commented Oct 12, 2020

Probably, coordinate parser is not taking scaling into account. Use explicitly relative axis coordinate system

every axis x label/.append style = {at={(rel axis cs:1.0, -0.2)}, },

@Rmano
Copy link
Author

Rmano commented Oct 12, 2020

Ah, ok. That way it works. rel axis cs: is supposed to be the default; it seems that fill between somehow changes this.

Thanks for the workaround!

@marmotghost
Copy link

marmotghost commented Oct 13, 2020

I agree with @ilayn. However, one lesson I learnt is to never add transformations to the ambient tikzpicture. Much worse problems can arise. If you add scale=0.6 to the options of the axis, the problem disappears. One seems to need to transform the nodes separately, though.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
                \begin{axis}[scale=0.6,
					nodes={scale=0.6},
                    width=6cm, height=6cm,
                    xmin=350, xmax=1100,
                    domain=300:1000, samples=100,
                    ymin=0, ymax=1,
                    axis x line = center,
                    axis y line = center,
                    enlarge x limits,
                    enlarge y limits,
                    xlabel = {$\lambda$~(\si{\nm})},
                    every axis x label/.append style = {at={(1.0, -0.2)}, },
                    ylabel = {$\xi_r$},
                    legend style = {nodes={right, font=\scriptsize}},
                    legend pos = north east,
                    clip mode = individual,
                    ]
                    \addplot [ultra thick, green!50!black, name path=A, domain=450:800] {exp(-(x-600)/400*(x-600)/100)};
                    \path [name path=B] (450,0) -- (800,0);
                    \addplot [green] fill between [of=A and B];
            \end{axis}
\end{tikzpicture}
\end{document}

Screen Shot 2020-10-12 at 8 11 20 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants