Code covered by the BSD License  

Highlights from
sciencestagram

image thumbnail

sciencestagram

by

 

07 Jun 2013 (Updated )

Make your plots look somewhat like they came from the dustiest section of the engineering library.

sciencestagram(figurehandle)
function [] = sciencestagram(figurehandle)
% sciencestagram(figurehandle) is a powerful (relatively weak and clunky) 
% tool for transforming (obfuscating) your data and giving it that hip new 
% retro look.  If your data are lacking in quality or pizzazz, simply type
% 'sciencestagram' into the command line to give your work a sense of
% staying power.  It'll have you saying "Goodbye zippy colors, hello 
% antiquated serifs!"
% 
% USAGE: Simply type 'sciencestagram' into the command line or include it
% in your script.  Include the optional argument figurehandle to specify
% exactly which figure to sciencestagram. 
% 
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
% EXAMPLE: 
% Create two identical plots; apply sciencetagram to the second:
% 
% % Create example line data:
% x = 1:100;
% y1 = 90*x;
% y2 = x.^2;
% y3 = .01*x.^3;
% 
% % Create example point data:
% x2 = [20 40 60 80];
% y4 = 1000*[5 6 4 3];
% y5 = 1000*[1 4 7 6];
% 
% % Plot the example data: 
% figure(1);
% plot(x,y1,x,y2,x,y3,x2,y4,'.',x2,y5,'*');
% title('On the Increasing Property of Numbers')
% ylabel('dependent variable')
% xlabel('independent variable')
% legend('y1 data','y2 data','y3 data','y4 data','y5 data','location','northwest')
%
% figure(2); 
% plot(x,y1,x,y2,x,y3,x2,y4,'.',x2,y5,'*')
% title('On the Increasing Property of Numbers')
% ylabel('dependent variable')
% xlabel('independent variable')
% legend('y1 data','y2 data','y3 data','y4 data','y5 data','location','northwest')
% sciencestagram; 
% 
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
% sciencestagram was created by Chad A. Greene in May 2013.  It seems to
% work on Windows 7 running MATLAB R2011b.  
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
% 

% Check to see if a specific figure is identified for
% sciencestagramification.  Otherwise the current figure is used:
if exist('figurehandle','var')
    set(0,'currentfigure',figurehandle);
end

cf = get(gcf,'children');
linewidths = [3 .5 1.5]; % it'll loop through these linewidths.
linestyles = ['- ';'--';': ';'-.']; % and these linestyles
markerstyles = ['p','.','x','+','s','^','o','d','v']; % and these markerstyles.

% Loop through all the children of the figure: 
for nf = 1:length(cf)
    set(gcf,'currentaxes',cf(nf))
    ca = get(gca,'children');
    
    % And loop through all the children of each axis: 
    for na = 1:length(ca)

        if isfield(get(ca(na)),'marker') 
            if strcmp(get(ca(na),'marker'),'none')==0
            set(ca(na),'marker',markerstyles(1+mod(na,length(markerstyles))),...
            'color','k');
            end
            
            if strcmp(get(ca(na),'marker'),'.')
                set(ca(na),'markersize',16); 
            end
        
        elseif isfield(get(ca(na)),'linestyle')
            if strcmp(get(ca(na),'linestyle'),'none')==0 && ~isfield(get(ca(na)),'CData')
            set(ca(na),'linewidth',linewidths(1+mod(na,length(linewidths))),...
            'linestyle',linestyles(1+mod(na,length(linestyles)),:),...
            'color','k');
            end
        
        elseif isfield(get(ca(na)),'CData')
            colormap(gray(4));

        end

    end

% Note that century schoolbook is pretty nice, but the painters renderer
% does not support it, meaning you might not be able to export to pdf.
set(gca,'fontname','century schoolbook',...
    'color','none')
box off

ht = get(gca,'title');
set(ht,'fontname','century schoolbook','fontsize',12);
hx = get(gca,'xlabel');
set(hx,'fontname','century schoolbook');
hy = get(gca,'ylabel');
set(hy,'fontname','century schoolbook');
hz = get(gca,'title');
set(hz,'fontname','century schoolbook');
hl  = findobj(gcf,'Type','axes','Tag','legend');
set(hl,'box','off')

end

% Now bring in da noise:
% (Image taken from a scan of the title page of Rayleigh's Theory of Sound)
hi=axes;
image(imread('theoryofsound.jpg'));
uistack(hi,'bottom') 
set(gca,'position',[0 0 1 1]) ;
box off;
set(gca,'xtick',[],'ytick',[]);

end

Contact us