Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I export a higher resolution image of a Mathematica Graph object?

How do I export a re-sized version of the output I get from a call to GraphPlot (or TreePlot if they produce different output) to a jpg file?
Currently, I'm simply calling Export[file_name, G] where G is the result from a call to something like GraphPlot. I'm using Microsoft office picture manager to view the jpgs, but re-scaling them there yields unsatisfactory results due to poor resolution (the graph I'm trying to plot has strings as labels which can't be made out after rescaling this way). I would like to be able to choose the size/resolution of the rendered jpg.

like image 833
David Perlaza Avatar asked Dec 12 '11 08:12

David Perlaza


People also ask

How do I increase the resolution of a plot in Mathematica?

For using Plot , the "resolution" of the plot can be changed by adjusting PlotPoints and MaxRecursion . This code shows what happens as you change those values. The black points are the points that Plot is using to draw the curve. Of course, in your final plot you probably won't want to show those black dots.

How do I export an image from Mathematica?

Select the graph by clicking the graph or the cell, then select File ▶ Save Selection As. In the Save As dialog box, select the file type in the Save as type: dropdown menu. Here, the graphic is saved as a JPEG: You can also simply use Copy and Paste to export a graphic.


2 Answers

As Simon already pointed out, don't use a raster-format for a vector-graphics. Instead, export you plot to e.g. a scalable vector graphics:

graph = GraphPlot[ExampleData[{"Matrix", "HB/can_292"}, "Matrix"]];
Export["graph.svg", graph]

The advantage is, that in such an image, you can still adjust and change lines, polygons and colors. And finally, you can export it to an image of arbitrary quality easily.

enter image description here

And remember, for Plots which contain lines, polygons, ... everything with sharp edges you should never use jpg. General speaking, this is a format for photographs only since its compression is made for reducing filesize in natural images. In those images you don't recognize the compression, in images with text, lines and polygons you certainly will notice the artefacts. Use png if possible. Take your browser and zoom into the above image.

like image 134
halirutan Avatar answered Sep 20 '22 16:09

halirutan


You can set both image size and compression level of the exported file by doing something like

Export[file_name, G, ImageSize -> 1200, "CompressionLevel" -> 0]
like image 20
Heike Avatar answered Sep 17 '22 16:09

Heike