# pgfplots/tikz externalize to avoid memory cap not functioning

I'm trying to use tikz and pgfplots to draw graphics made in R using ggplot but I've been running into the memory cap in TeX:

TeX capacity exceeded, sorry [main memory size=3000000]. \end{tikzpicture}


what seems to be happening is the graph is too large and the memory for compiling the document is maxed out, there is apparently an externalize function that builds the plots individually but I can't get it to work, I'm still getting a memory full error after calling the external function. I've enabled shell escape for this document and attempted the code seen below in addition to trying to use the pgfplots external function.

% !TeX document-id = {7d5430ab-11da-4426-8450-fdab6517066c}
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass[]{article}
\usepackage[left=3cm, right=3cm, top=2cm]{geometry}
\usepackage{pdflscape}
\usepackage{longtable}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]
\usepackage{eurosym}
\usepackage{pgfplots}
\usepackage{shellesc}

% need to use external package to build each graphic separately so they don't
% max out latex's memory

\tikzexternalize

\pgfplotsset{compat=1.16}


I found what seemed to be a promising answer on this site in

but this solution no longer seems to work, \usepgfplotslibrary{external} no longer refers to anything, which is not surprising given the answer is almost 10 years old, and the tikz externalize function also does not work, I still get the memory limit error message . I'm using the MiKTeX distribution with the TeXStudio editor if that matters. I've cut back the complexity of the graph that triggered this issue but it doesn't seem to have resolved anything, and I need to add more graphics so I'm not sure raising the memory limit would help- any help would be appreciated.

EDIT: clarified error message and some other corrections based on feedback from schtandard

• Welcome to TeX.SX! Please make your code snippet an MWE that we can test. What exactly does "does not work" mean? Are you getting any error messages? Why are you calling \tikzexternalize twice? Does the folder tikz/ exist? – schtandard Sep 8 '19 at 6:36
• When I have this issue, as I am running on miktex, i use the --extra-mem-top=... and --extra-mem-bot=... options. – BambOo Sep 8 '19 at 12:27
• Also after editing your question we still don't know if the folder tikz/ does exists and why you call \tikzexternalize twice. And most importantly we you still didn't provide a minimal working example (MWE) so we can reproduce your problem and maybe find an answer. Sorry, without more detailed information it is very unlucky that someone will be able to help you. – Stefan Pinnow Sep 9 '19 at 5:02
• Both the tikz/ folder and calling \tikzexternalize twice were user error on my part, removing the extraneous command and providing a folder both had no effect. I thought externalize was not loading but after implementing BambOo's solution the graph still will not compile with the maximum extra memory my compiler will load. My graph has too many datapoints to compile on my current system, I had not realized that a large number of points was an issue for tikz and pgf plot, I'm going to have to export the graph as a png. Thank you for the help. – Daniel Wagner Sep 9 '19 at 5:54
• Perhaps one more note: The memory issue usually only arises when you are using PDFLaTeX. If you would use LuaLaTeX then it should work. – Stefan Pinnow Sep 10 '19 at 4:10