%Example 17.4a (Physics 330) clear;close all; x=0:0.05:2*pi; f=sin(x); data = f + rand(1,length(x))-0.5; err_hi = f + 0.5; err_low = f - 0.5; % Choose what size the final figure should be Units = 'Centimeters'; figWidth = 8.5; figHeight = 7; % Create a figure window of a specific size. % Note that we also get a handle to the entire figure (ff) for later use ff = figure('Units',Units,'Position',[10 10 figWidth figHeight]) % Plot the data and get handles to the lineseries objects. pp=plot(x,f,'b',x,data,'b.',x,err_hi,'r-.',x,err_low,'g--'); % Set the lineseries visual properties. set(pp(1),'LineWidth',2); % Make the main sine a heavy line set(pp(2),'MarkerSize',8); % Make the dots a bit bigger than default set(pp(3),'LineWidth',1); % Make the error bound lines slightly heavier set(pp(4),'LineWidth',1); % Make the error bound lines slightly heavier % Set the plot limits and put on labels axis([0 2*pi -1.6 1.6]) xlabel('\theta') ylabel('sin(\theta)') title('Fake measurement of Sine function') % Get a handle to the axes and set the axes visual properties aa=gca; set(aa,'FontSize',8,... % Set the font for the axes 'FontName','Symbol',... % to get pi in labels (p is pi in symbol font) 'LineWidth',1,... % Make the border around the figure heavier 'TickLength',get(aa,'TickLength')*2,... 'XTick',[0 pi/2 pi 3*pi/2 2*pi],... % Specify where the ticks go 'XTickLabel',{'0';'p/2';'p';'3p/2';'2p'},... % custom tick labels 'XMinorTick','On',... 'YTick',[-1 -.5 0 .5 1],... 'YMinorTick','On') % Put in a legend. We have to specify the font back to Helvetica (default) % because we changed to the symbol font above for the pi tick labels. ll=legend('Sine','Fake Data','Upper Limit','Lower Limit'); set(ll,'FontName','Helvetica') % Set the output size for the figure. % DO THIS LAST because the margins will depend on font size, etc. % Set the outside dimensions of the figure. set(aa,'Units',Units,'OuterPosition',[0 0 figWidth figHeight]) % Calculate where the axes box should be placed inside the overall figure. newPos = get(aa, 'OuterPosition') - ... get(aa, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]; % Now set the position of the axes box within the figure set(aa, 'Position', newPos); % As a finishing touch, draw a proper rectangle around the plot area % (The box matlab draws has lines that don't join in sharp corners...) Bound = annotation(ff,'Rectangle',[0 0 1 1]); set(Bound,'Units',Units,... 'Position',get(aa,'Position'),... 'LineWidth',1);