The pgfplots package can be particularly heavy on TeX's memory, especially if you are creating plots with lots of data points. Indeed, there is a section in the pgfplots manual about expanding TeX's memory. However, that does not mean that expanding TeX's memory is the best solution. Instead, I would recommend using the 'externalization' approach (section 7.1 of the pgfplots manual).
The idea of externalization is to compile each plot as a separate TeX job. This leads to a graphic which can be used in the main job. Thus each plot has its own memory requirement, separate from all of the other plots. This usually avoids needing to make TeX's memory bigger. At the same time, the resulting files can be kept between TeX runs, which will speed up compilation for the second and subsequent runs. The latest version of the externalization system needs you to do two things. First, you put
\usepgfplotslibrary{external}
\tikzexternalize
in your preamble, to turn the system on. Secondly, you will need to enable 'shell escape'. This is done at the command line by adding the -shell-escape switch:
pdflatex -shell-escape <filename>
The same can be done in LaTeX editors: there is usually a place in the settings for this type of thing. I'll just add that shell escape does has some security implications: use only with documents that you trust!