Generating High Quality Plots in Matlab
Recently I have been dabbling with generating plots in Matlab in order to present some of my current data, and being a beginner to Matlab, and coding in general, I have come across a few useful tricks, although with the flexibility that Matlab offers, I have surely only scratched the surface in terms of making high quality graphs!
Dots Per Inch (DPI)
When saving a plot in Matlab, there are several ways to go. You can of course run your code, generate your plot and then save it manually within the figure GUI that will automatically pop up; however for the most automation and control of your end product, it is best to "print" (save is this instance) your figure using a bit of code.
print -dpng -r600 testplot600.png
Now here is where you can go wild formatting your figure to various parameters (from RGB/CMYK/Black & White, to resolution, output file type, printer selection...etc). For a more complete list of the available parameters and options just type in:
...and you will get a good explanation of how to use the print command.
The command "-dpng" specifies the output file type. Here you can select from a multitude of image file types (i.e. jpeg, bmp, tiff...etc) or other file types such as PDF's.
The command "testplot600" specifies the output file name.
The command "-r600" specifies the DPI value. A higher DPI value results in a higher resolution image, making edges smoother and the overall aesthetic more appealing. Here are some examples of different DPI values (150, 300, 600, 900 dpi)
The difference between the 150-300 DPI figures and the 600 DPI figure is quite noticeable whereas the difference between that and the 900 DPI figure is a little more subtle. The image is crisper, however it is worth noting that the higher quality you render your images, the longer it will take to process.. however this is well worth the extra few moments in order to get the best quality image in your manuscript, poster, presentation..etc. You can in fact choose to render your images with an even higher DPI value, however the difference get less and less noticeable until there is in fact no noticeable difference to be seen, as viewing monitor have a maximum resolution. At this point though, your image will surely be satisfactory.
A note about the shaded error regions in the sample data above.
Some of you may be interested in using similar shaded areas in your plots, they are a great alternative to typical error-bars, and I believe offer a clearer visual representation of the data's variance and in comparing different data. To get the above figures I utilised a function called "shadedErrorBar.m" found on Matlab Central's File Exchange written by Rob Campbell ( http://www.mathworks.com/matlabcentral/fileexchange/26311-shadederrorbar ) .
As I mentioned, there is way more that you can do in generating your figures. These tips will help you render high quality images easily, and in the format you desire!