Making good figures in matlab takes a little work. There are several things
matlab does by default that can make the printed figure look terrible. The
following matlab code shows how to overcome all of the following:
(1) specifying figure size so that re-scaling doesn't make fonts look bad
(2) removing matlab's extra whitespace surrounding figure
(3) setting the font sizes to 12 (or other) on axes labels
(4) scaling the range of axes to fixed values (for consistency plot to plot)
(5) displaying bars/lines in different grey values, instead of color
(6) using different line thicknesses, dash/dot, etc.
(7) plotting multiple things in a single figure
(8) setting up working directory and filename for figure generation
(9*) although not pictured, notice I am not specifying a caption; leave
this out as you will likely insert a caption in LaTeX with the figure
Simply typing "plot(x)" is not sufficient, and in most cases makes
for a terrible figure. You have to take it all the way to paper and adjust
things as needed to make it look good.
For every figure you create, save the matlab code (like the attached) so
that you or I can go back at any time and easily re-create the figure.
During paper submission, review, revisions, etc., this makes life easier.
------------------------------------ MATLAB code ----------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set up working directory and filename for figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cd C:\Writing\Publications\state\matlab
filename='gauss-fit'; % extension specificed below
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% set up figure size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% By default, matlab prints a figure as 4 (width) x 3 (height) inches.
%% On US paper, a two-column figure is typically 3.5 inches wide and a
%% one-column figure is typically 6.5 inches wide (heights will vary).
%% Importing a figure of the default size into LaTeX and then scaling it to
%% fit makes the fonts shrink or expand, and makes the figure look bad.
%% This stuff sets up the figure area to a specific width x height.
figure(1); % select figure pane
set(gcf, 'PaperUnits', 'inches'); % units
width=3.5; % width of figure
height=width*0.75; % 75% width keeps default ratio
set(gcf, 'PaperPositionMode', 'manual'); % turn off 'auto' so it doesn't resize upon printing
papersize = get(gcf, 'PaperSize'); % for US paper, 8.5 x 11
left = (papersize(1)- width)/2;
bottom = (papersize(2)- height)/2;
set(gcf, 'PaperPosition', [left bottom width height]); % middle of page
%% By default, matlab surrounds a figure with extra whitespace.
%% This stuff sets up the 3 axes to contract that whitespace.
%% See http://nibot-lab.livejournal.com/73290.html
%set(gca, 'Position', get(gca, 'OuterPosition') - get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);
set(gca,'LooseInset',get(gca,'TightInset')); % this works better
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% create figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=-4.0:0.2:4.0; % 40 element array, values = -4.0 -3.8 .3.6 ... +3.8 +4.0
y=randn(1000,1); % 1000 random numbers with mean=zero, stddev=1.0
f=histc(y,x); % 40 element histogram of the random numbers, binned by x
% bar(x,f,'Color',black); % bar-plot of the histogram in black
h=bar(x,f); % same bar-plot command, but without color
set(h,'facecolor',[0.7,0.7,0.7]) % this changes the colors of the bars
% compute the denominator in fitting the Gaussian
for i=1:41,
d(i)=(exp(1)^((-x(i)^2)/2))^2;
end
% compute the numerator in fitting the Gaussian
for i=1:41,
n(i)=f(i)*(exp(1)^((-x(i)^2)/2));
end
% compute K for the Gaussian
k=sum(n)/sum(d);
% create a set of values using the computed K in order to plot the Gaussian
for i=1:41,
s(i)=k*(exp(1)^(-(x(i)^2)/2));
end
hold on % tells matlab not to clear window
plot(x,s,'black','LineWidth',4) % plot the computed Gaussian fit
xlabel('x','FontSize',12); % x-axis label
ylabel('freq(x)','FontSize',12); % y-axis label
set(gca,'FontSize',12); % change the font for the ticks
axis([-4 4 0 90]); % scale the axes to this size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% done creating figure
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% print figure to file (-deps for greyscale, -depsc for color, -dpdf for pdf, etc.)
print('-f1','-deps',filename);