Add legend to pgf plot results in \end{axis} error
Expanding my comment to an answer.
The problem is in the use of forget plot
.
Due to the fact pgfplots
shall forget each plot, but on the other hand defining a legend entry for each plot, pgfplots
doesn't know what to do.
To solve the problem two possibilities are given, based on the desired result.
Remove all
\addlegendentry
from the different plots, so no legend will be plotted.Remove -at least one-
forget plot
to plot the legend.