I've made around 50 plots of stochastic processes for my master thesis (using ListLinePlot, see figure and code below). Individually, they aren't very heavy (1 to 4MB), but, adding everything up, the final PDF file of the thesis is 84MB above my university's limit.

Is there any way to decrease the file size of the plots without rasterizing them? Clearly we can't even see most of the points, hidden under the line thickness itself. Is there any way to decrese the "resolution" of a vector image?

Rasterizing them with an acceptable resolution and converting to JPEG creates files about 1/4 of the original size--which is barely enough--, but I would like to avoid that.

E.g. the original (not rasterized) of this plot is 1.2MB. Each line has 30k data poits (some plots are longer, therefore heavier):

PDF rasterized to JPEG

The lines being slightly transparent serves a function. They are also quite thick because I am comparing many of such graphs side-by-side.

The plots are generated as follows:

plot[\[Rho]_]:= Labeled[ListLinePlot[{
     {ts, \[Rho][1]}\[Transpose],
     {ts, \[Rho][2]}\[Transpose]},
    PlotStyle -> {
      RGBColor[52/255, 43/255, 224/255, 0.6],
      RGBColor[205/255, 101/255, 0/255, 0.7]},
    PlotRange -> {{0, 30}, {-0.05, 1.05}},
    DataRange -> {dt, 30},
    ImageSize -> 400,
    AspectRatio -> 2/5,
    GridLines -> {None, {0, 1}},
    Frame -> True
   Style["Monitorando qubit " <> ToString[qb] , 14, "Text"],
   Left, RotateLabel -> True, Alignment -> Center];

Each \[Rho][i], i=1,2, is a list of 30k values (y-axis), and ts = Range[0.001, 30.0, 0.001] (x-axis).


1 Answer 1


Since 30,000 points are not visible, the easiest thing is to subsample data curves into a max & min trajectory and fill the space between. To illustrate, create a data set:

data = Table[{x, Sin[x]}, {x, 0.0, 10, 1.0/3000}]; Dimensions@data {30001, 2}

This has 30,000 points. For illustration, we extract the mean of the x-values and the min & max of the y-values.

meanX = Mean /@ Partition[First@Transpose[data], 1000]; minY = Min /@ Partition[Last@Transpose[data], 1000]; maxY = Max /@ Partition[Last@Transpose[data], 1000]; Dimensions@meanX


In reality, a couple hundred points would be more reasonable than 30. Plotting this,

basic filled plot

Show the concept. Now you just need to adjust the colors and you are good to go:

styled plot

I'd ditch PlotHighlighting which should NOT be turned on by default since it doesn't scale well. 400 pixels (x-bins) are all that can be seen on the screen so my graphics will automatically use "SmallPlot" as a foundation. This should reduce your graphic footprint by a factor of 100.

  • $\begingroup$ Thank you! I'll probably have to think about some way to implement it for points close together (most of them), while not averageing out the random fluctuations. But this already gives me some ideas, thank you again! $\endgroup$
    – luizuc
    Mar 10 at 1:51
  • $\begingroup$ If you use the max and min of the y-values for each of the x-value bins and fill between them, you will be displaying the extrema and not lose any fluctuations. You just want to have the max & min curves to have a common x-value and the mean of the bin is sufficient for that. $\endgroup$ Mar 10 at 17:55
  • $\begingroup$ Just to give you some feedback, this method did not work well for my stochastic plots. It looked very weird. I think that even though most poits were sobreposing each other, a few random ones (by construction) were very off. Your method made random 1-datapoint-long jumps into triangles with the width of the partition. $\endgroup$
    – luizuc
    Mar 13 at 19:40
  • 1
    $\begingroup$ Fortunately, I found a solution: the dataset was actually way longer than what I was ploting (the remaining data was used in a histogram). Even though I restricted the DataRange, Mathematica was saving the information of the remaining 97% of the points into the graph's PDF. By shortening the list before inputing it into ListLinePlot, I reduced the file size by 97%. I didn't know that that could happen. $\endgroup$
    – luizuc
    Mar 13 at 19:43
  • $\begingroup$ At any rate, thank you very much for the help. I think that with some extra care, I could use adapt your method. (I didn't mentioned it in the other comment, but for the fluctuations to preserve their shape, the partitions needed to be so short that the final file size was negligibly smaller) $\endgroup$
    – luizuc
    Mar 13 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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