# Area restricted by three functions

I am trying to shade the area restricted by the functions y \sin x, x = \sin y and y = 2pi + x. Now my problem is that I do not have access to Pgfplots 1.10so the libary fillbetween is not accessible to me. I have attempted to plot the area below using

\documentclass[a4paper,12pt]{standalone}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.10}
%\usepgfplotslibrary{fillbetween}

\begin{document}
\pgfplotsset{every axis legend/.append style={
at={(0,0.99)},
anchor=north west}}
\begin{tikzpicture}
\begin{axis}[
xmin=-2.5*pi,xmax=pi,ymin=-pi,ymax=2.5*pi,
domain=-2pi:2pi,
samples=100,
xlabel={$x$},
ylabel={$y$},
yticklabels={,,},
xticklabels={,,},
axis lines=middle
]
\addlegendentry{$y =x + 2\pi$}

\addlegendentry{$y =x + 2\pi$}
\addlegendentry{$y =x + 2\pi$}
%\addlegendentry{$x = \sin y$}
]\end{axis}
\end{tikzpicture}
\end{document}


I have tried to mark the parts on the figure I am having problems with. All of them are related to how I am shading the figure. The idea I am using is to first fill in the entire triangular area under x + 2\pi, and then fill in white where needed.

• Why must i use opacity=0.1 for the first function and opacity=0.2 for the second function to obtain the same color gray? Is this a problem on my end?
• Why is the x-axis unneven, eg higher between -pi and 0 ? Same with y-axis.
• Labels, why are the first and last label correct, but the middle one is always gray?

I think the labeling problem is a minor problem caused by how I fill the various parts of the figure. But still it is quite weird that the first and second legends are fine. So to summarize, is there a better method for shading the area gray? I have tried the method provided here filling area between 2 functions, with shading, but alas this crashes every time I try to invoke the sine function, and not sure how to handle the implicit function using this method.

• There is an extra black after the in the first function. I suppose this overrides the defined fill colour (gray), and black with opacity=0.1 is about the same as gray with opacity=0.2.
• It is because of the filling I think, which covers up half of the axis width. For x < -pi/2 the top half is covered, for x > -pi/2 the bottom half is covered, leading to the small 'step'. You can fix this by placing the fill on the background layer.
• \addlegendentry picks up the plots in the order they are defined, regardless of where they are placed, so it is the first three \addplots that are shown in the legend. The forget plot key removes a plot from the legend I believe.

You have a spurious ] just before \end{axis} by the way.

In the code below I plot the lines first, then add the fill on the background layer using the backgrounds library from TikZ.

\documentclass[a4paper,12pt,border=3mm]{standalone}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.10}
\usetikzlibrary{backgrounds}
\begin{document}
\pgfplotsset{every axis legend/.append style={
at={(0,0.99)},
anchor=north west},
cells={anchor=west}}
\begin{tikzpicture}
\begin{axis}[
xmin=-2.5*pi,xmax=pi,ymin=-pi,ymax=2.5*pi,
domain=-2pi:2pi,
samples=100,
xlabel={$x$},
ylabel={$y$},
yticklabels={,,},
xticklabels={,,},
axis lines=middle
]

\addlegendentry{$y = x + 2\pi$}
\addlegendentry{$y = \sin x$}
\addlegendentry{$x = \sin y$}

\begin{scope}[on background layer]