Skip to main content

export - Saving high-quality graphics through commands


Say I make and display a graph in a Mathematica notebook:


graph = CompleteGraph[100]


If I drag the corner of the graph to increase its size, and then save it to a file, I get a really big detailed picture of the graph. This is great! I would like to do this without the dragging interaction. Specifically, I want to generate really big graphs and save very detailed images of them by script.


I tried using ImageResize on the graph:


Export["mysuperawesomegraph.png", ImageResize[graph]];

But it seems that the graph object is converted to an image (graphics object) which is scaled up and then saved - so the level of precision in the resulting image is no greater than if one were to call:


Export["mysuperawesomegraph.png", graph];

and manually scale up the image outside Mathematica.



Answer



Control image size as Graph option:



g = CompleteGraph[100, ImageSize -> 2000];
Export["mysuperawesomegraph.png", g]

Also if you already have graphics produced, you can use Show to programmatically resize it:


g = CompleteGraph[100, GraphStyle -> "LargeNetwork"];
gmag = Show[g, ImageSize -> 2000];
Export["mysuperawesomegraph.png", gmag]

In Mathematica there is a difference between Graphics objects and images:


RandomImage[1, {100, 100}]


enter image description here


In[1]:= % // Head
Out[1]= Image

Graphics[Raster[RandomReal[1, {100, 100}]]]

enter image description here


In[2]:= % // Head
Out[2]= Graphics


ImageResize is used for images and may result in the loss of resolution. Changing shown size of Graphics with Show will not result in loss of resolution.


Comments