I saw a plotting style that I really like and I am trying to recreate it. I am having troubles getting that crisp style and am having problems with the semi-transparent gray borders.
I tried to recreate it but I turned on transparency for the whole thing using \pgfsetfillopacity{0.5} which doesn't look great.
Additionally, the grey boxes have manual coordinate. How do I set the box coordinates relative to the frame instead of the data coordinates?
The plot that I'm trying to copy
The code I made and how it looks
\begin{tikzpicture}
\begin{axis}[
height=7cm,
width=11cm,
grid=major,
xmin=-0.5,
xmax=20.0,
ymin=-0.6,
ymax=0.6,
xlabel={Time [$s$]},
ylabel={Position [$m$]},
thick,
legend columns=-1,
legend style={/tikz/every even column/.append style={column sep=0.5cm}},
y tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1,
/tikz/.cd
},
x tick label style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1,
/tikz/.cd
},
every axis/.append style={font=\small}
]
% Cool looking borders ??
\pgfsetfillopacity{0.5} % ??
\draw[line width=0.4pt, fill=gray] (-0.5,-0.6) rectangle (20,-0.45);
\draw[line width=0.4pt, fill=gray] (-0.5, 0.6) rectangle (20, 0.45);
% Add sine and cos plots
\addplot[color=blue, samples=65, domain=0:20]{0.1 * sin(2 * pi * 10 * x)};
\addplot[color=orange, mark=*, domain=0:20]{0.1 * cos(2 * pi * 10 * x)};
% Add legends
\addlegendentry{Element 1};
\addlegendentry{Element 2};
\end{axis}
\end{tikzpicture}
What I end up with is a bit different. I didn't find anything for the opacity thing.



\draw (xmin, ymin) rectangle (xmax, 0.8*ymin);– Speterius Jan 31 '22 at 06:55\pgfkeysvalueof{/pgfplots/xmin}in a\drawcommand like that. Equivalently for the other limits. – Torbjørn T. Jan 31 '22 at 06:58