Tuesday, April 5, 2011

Making good-looking Matlab figures

One of the reasons why I like Matlab so much is that you can do everything there; from simulations, data processing, calculations all the way to making graphs and figures to show your results. Everything in one package!

But frankly, the graphs that Matlab spits out with the default settings are pretty ugly. Let me make an example. I generated some data ( y = log10(x)*x ) and added some noise. The plot shows the theoretical curve and the "data".

This looks ok, but to me, the lines are too thin and the font does not look good. First, let's change the size of the output. 

I have learned that it is much easier to set the size of a Matlab figure in physical sizes (centimeters) than the default. The following code sets the figure to be 15x12 centimeters.

    set(gcf, 'PaperUnits', 'centimeters');
    set(gcf, 'PaperSize', [15 12]);
    set(gcf, 'PaperPositionMode', 'manual');
    set(gcf, 'PaperPosition', [0 0 15 12]);

Applying this to our figure we get

Looks better, right? Now, let's change the font-size, the line-width and the length of the tickmarks.

Change the ticklength. Use a value close to [0.02 0.025], but you may have to experiment with smaller or larger values for the first parameter (between 0.015 to 0.025) to make it look good.
set(gca, 'TickLenght', [0.02 0.025]);
Change the font size. For a figure of this size, 10 points looks good.
set(gca, 'FontSize', 10);
Change the linewidths of the axes and of the objects plotted.

 set(gca, 'Linewidth',1);
and the same for the other handles.
Compared with the first graph, this is a clear improvement. 

This will be all for now. In this post I used png files. When making figures for research papers it is required that they use the eps format. There are a few more tweaks that can be made to such figures. 

No comments:

Post a Comment