# Save ArrayPlot in vector format as PDF?

ClearAll[spiral];
spiral[n_?OddQ] :=
Nest[With[{d = Length@#, l = #[[-1, -1]]},
Composition[Insert[#, l + 3 d + 2 + Range[d + 2], -1] &,
Insert[#\[Transpose], l + 2 d + 1 + Range[d + 1],
1]\[Transpose] &,
Insert[#, l + d + Range[d + 1, 1, -1], 1] &,
Insert[#\[Transpose],
l + Range[d, 1, -1], -1]\[Transpose] &][#]] &, {{1}}, (n -
1)/2];

spiral[351] // PrimeQ // Boole // ArrayPlot
Export["Color351.pdf", %]


Code is from other post on the forum, credit to the OP. The question is, the exported PDF does not seem to have saved the graph in a lossless vector format.

This is what I get from the adobe acrobat:

If you go back and look at the picture from MMA10.2 X64 (win7), we can zoom in/out, the graph is still very sharp, in high resolution.

If there a way to save/export it with much higher quality?

Thanks.

I suspect that the fuzziness you see might not be caused by rasterization, but rather by antialiasing applied to the ArrayPlot markers. Anti-aliasing makes the edges of small graphical elements fuzzy to avoid jaggedness, and it is typically a good thing that generates visually pleasing results. In your case, however, the very small plot markers present in a default sized ArrayPlot get antialiased to this shape, when looking at the PDF generated by your code under maximum zoom:

Note that this effect is not visible in MMA if I zoom in to the plot, as the plot is evidently redrawn at the appropriate dimensions after zooming, and the effects of anti-aliasing are not as prominent on larger features.

I was able to get crisper results simply by requesting a larger output from ArrayPlot, and then exporting that:

spiral[351] // PrimeQ // Boole // ArrayPlot[#, ImageSize -> Large] &
Export["Color351Large.pdf", %]


Here is the a blown-up view of a similar portion of the graph from the exported "Color351Large.pdf":

• In terms of visual, the blow-up version does look much better now. Purely for the sake of the question, is there an easy way to get the graph as a vector format? Your version in the default scale looks a bit fuzzy, especially at the edges since the graph is still exported as an "image". – Chen Stats Yu Sep 17 '15 at 5:52
• @ChenStatsYu I am not in front of my computer now, so I will have to check more carefully tomorrow, but I am quite convinced that the exported graph in the PDF was in fact in vector format already. Maybe you could upload an image of the fuzzy part you see. Alternatively you could try exporting your graph as and EPS file. – MarcoB Sep 18 '15 at 4:18