The tikzscale package overloads the \includegraphics command, uses a bounding box to calculate the size of a pgfplots plot, and adjusts the size of the plot such that the target height and width are met, while preserving font sizes. This approach works well unless you have \subcaption{} and \label{} embedded in the figure, which results in multiply-defined labels.
- Add the following code to your preamble.
<unique name>should be replaced by an appropriate toggle name.\newtoggleshould be repeated for every figure containing a plot, each with a unique name.
\usepackage{etoolbox}
\newtoggle{}