I am trying to do an overlay of a scatterplot and a barplot. When I try to execute my code, I get, TeX capacity exceeded, sorry [main memory size=3000000]. \pgfplotsapplistXXpushback@smallbufoverfl ...toka

The csv files are here: file1file2 Can latex handle the data? Excel can, why can't latex? Thanks for your help.

\pgfplotsset{compat=newest,width=\textwidth,xlabel={fractions},ylabel={Phospho hits},cycle list name=color list,legend columns=2}

\addplot table [ybar,col sep=comma, x=fractions, y=Phospho] {SCX1.csv};
\addplot table [col sep=comma, x=min, y=mv] {SCX01-HPLC.csv};


Because it exceeds the memory. In the first csv you've got 39768 rows, which are a lot! There are two ways:

  1. Compile your document with lualatex (takes 8 seconds on my computer)

output with lualatex

  1. Use this decimated csv with "only" 3060 points obtained from your old csv and compile with pdflatex (takes about 2 seconds):

decimated data with pdflatex

Can you see any difference? I don't!

To reduce the sampling of you data I've used Matlab, but I'm sure there are also other ways. Suppose the name of your csv table is data.csv you can copy and paste it onto Matlab to open the data import wizard and have the content in your workspace in a matrix variable that I've called mydata (the first row contains the x-vector and the second column contains the y-vector). To reduce the number of points you can (Matlab code):


To convert the output in a csv file:


et voila'! You have a new set of points which number is reduced by a factor of 13 that also pdflatex can handle.

Personal note: if you only need to plot this graph, just use lualatex but remember to include the pdf instead of the tex source. If you have many graphs (perhaps in the same figure), even though lualatex may be able to deal with the memory it would take ages to to write your report, and therefore I would go for the second option.

  • Thanks mirkom, your suggestion is appreciated. Unfortunately, I do not have matlab. I have R however. Would you be able to suggest a similar method in reducing the sampling rate using R? Also, is there a way to render the red plot (with less datapoints) as a bar graph? – Spencer Trinh Apr 22 '16 at 3:06
  • I'm sorry but I'm not familiar with R. You can download the csv I've linked in the answer, at least for this plot. For the bar plot, I see that there are some empty cells in SCX1. Are these zeros or what? Also, the red plot is only of 30 points. Not really a problem for pdfLaTeX therefore there is no need to reduce the points. – mirkom Apr 22 '16 at 3:20
  • You could try GNU Octave instead – 804b18f832fb419fb142 Apr 23 '16 at 0:35

According to your comment in mirkom's answer ... if you are a R user, why not do it with knitr?

A nice scatter plot in \LaTeX: 
<<echo=F,  dev='tikz', fig.width=6, fig.height=6>>=
read.csv("file1.csv") -> x
plot(x,type="l",xlab="fractions",ylab="Phospho hits", col="blue", lwd=2)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.