I am trying to draw an inset within the region of a pgf
plot by creating a second pair of axes, as can seen in the following code.
\documentclass{standalone}
\usepackage{tikz, pgfplots}
\begin{document}
\begin{tikzpicture}[scale=1., remember picture]
\begin{axis}[width=\textwidth,
height=0.65\textwidth,
ultra thick,
grid=both,
grid style={line width=.1pt, draw=gray!30, dashed},
domain=0:1.1,
xmin=0, xmax=1.1,
ymin=-300, ymax=160,
ytick={-250, -200, ..., 150},
xlabel=Deformation - $\alpha_2$,
ylabel=Energy (MeV),
ylabel shift = 2 pt,
filter discard warning=false,
unbounded coords=discard,
]
\addplot[smooth, thick] {100*x^3};
\node at (rel axis cs:0.9, 0.3) {Coulomb};
\addplot[smooth, thick] {-200*x^2};
%node[above right] {Surface};
\addplot[smooth, thick] {100*x^3-200*x^3+100*x^4};
%node[above right] {Net};
\coordinate (insetPosition) at (rel axis cs:0.15, 0.15);
\end{axis}
\begin{axis}[at={(insetPosition)},
small,
ultra thick,
grid=both,
grid style={line width=.1pt, draw=gray!30, dashed},
domain=0:1.15,
xmin=0, xmax=1.2,
ymin=0,ymax=5,
ytick={0, 1, ..., 5},
xlabel=Deformation - $\alpha_2$,
ylabel=Energy (MeV),
width=0.45\textwidth,
height=0.3\textwidth,
opacity=1,
]
\addplot[smooth] {0.568232*(2.3333*x - 1.22617*x^2 + 9.499768*x^3 - 8.050944*x^4)^2};
\end{axis}
\end{tikzpicture}
\end{document}
The problem is that the grid lines of the large plot, are visible through the inset, as suggested by the following image.
I tried using opacity=0
but the whole plot disappeared.
Any idea on how to make the inset opaque?