Code covered by the BSD License  

Highlights from
Attributed Plot Html

image thumbnail

Attributed Plot Html

by

 

This exchange file creates a clickable image map for a figure with links to multiple data sources.

EXAMPLE_marathons.m
%% Example data file that can be used as a source for AttributedPlotHtml.m

%This is an object oriented template for uploading data.

races = [];
Crux = [];

timeFormat = 'HH:MM:SS';

%% Data

% Boston 2012

bos2012.mtime = datenum('2:12:40',timeFormat);
bos2012.wtime = datenum('2:31:50',timeFormat);
bos2012.avgtime = datenum('4:18:27',timeFormat);
bos2012.tempavg = 73; %[F]
bos2012.linky = 'http://www.marathonguide.com/results/browse.cfm?MIDD=15120416';
bos2012.linkx = 'http://www.erh.noaa.gov/box/displayF6.php?Month=04&Year=12&Location=BOS';
bos2012.blurb = 'Boston Marathon April 16, 2012';

races.bos2012 = bos2012;

% Boston 2011
bos2011.mtime = datenum('2:03:02',timeFormat);
bos2011.wtime = datenum('2:22:36',timeFormat);
bos2011.avgtime = datenum('3:49:54',timeFormat);
bos2011.tempavg = 53; %[F]
bos2011.linky = 'http://www.marathonguide.com/results/browse.cfm?MIDD=15110418';
bos2011.linkx = 'http://www.erh.noaa.gov/box/displayF6.php?Month=04&Year=11&Location=BOS';
bos2011.blurb = 'Boston Marathon April 18, 2011';

races.bos2011 = bos2011;


% Boston 2010
bos2010.mtime = datenum('2:05:52',timeFormat);
bos2010.wtime = datenum('2:26:11',timeFormat);
bos2010.avgtime = datenum('3:50:25',timeFormat);
bos2010.tempavg = 51; %[F]
bos2010.tempmin = 40; %[F]
bos2010.tempmax = 61; %[F]
bos2010.linky = 'http://www.marathonguide.com/results/browse.cfm?MIDD=15100419';
bos2010.linkx = 'http://www.erh.noaa.gov/box/displayF6.php?Month=04&Year=10&Location=BOS';
bos2010.blurb = 'Boston Marathon April 19, 2010';

races.bos2010 = bos2010;


% Boston 2009
bos2009.mtime = datenum('2:08:42',timeFormat);
bos2009.wtime = datenum('2:32:16',timeFormat);
bos2009.avgtime = datenum('3:49:34',timeFormat);
bos2009.tempavg = 43; %[F]
bos2009.tempmin = 38; %[F]
bos2009.tempmax = 48; %[F]
bos2009.linky = 'http://www.marathonguide.com/results/browse.cfm?MIDD=15090420';
bos2009.linkx = 'http://www.erh.noaa.gov/box/displayF6.php?Month=04&Year=09&Location=BOS';
bos2009.blurb = 'Boston Marathon April 20, 2009';

races.bos2009 = bos2009;

% Chicago 2010
chi2010.mtime = datenum('2:06:24',timeFormat);
chi2010.wtime = datenum('2:20:25',timeFormat);
chi2010.avgtime = datenum('4:43:48',timeFormat);
chi2010.tempavg = 71; %[F]
chi2010.tempmin = 57; %[F]
chi2010.tempmax = 84; %[F]
chi2010.linky = 'http://www.marathonguide.com/results/browse.cfm?MIDD=67101010';
chi2010.linkx = 'http://www.nws.noaa.gov/climate/index.php?wfo=lot';
chi2010.blurb = 'Chicago Marathon October 10, 2010';

races.chi2010 = chi2010;

% Chicago 2009
chi2009.mtime = datenum('2:05:37',timeFormat);
chi2009.wtime = datenum('2:18:20',timeFormat);
chi2009.avgtime = datenum('4:40:34',timeFormat);
chi2009.tempavg = 46; %[F]
chi2009.tempmin = 39; %[F]
chi2009.tempmax = 52; %[F]
chi2009.linky = 'http://www.marathonguide.com/results/browse.cfm?MIDD=67111009';
chi2009.linkx = 'http://www.nws.noaa.gov/climate/index.php?wfo=lot';
chi2009.blurb = 'Chicago Marathon October 09, 2009';

races.chi2009 = chi2009;

% Tokyo 2013
tok2013.mtime = datenum('2:06:50',timeFormat);
tok2013.wtime = datenum('2:26:41',timeFormat);
%tok2013.avgtime = datenum('',timeFormat);
tok2013.tempavg = 40; %[F]
tok2013.tempmin = 46; %[F]
tok2013.tempmax = 33; %[F]
tok2013.linky = 'http://www.tokyo42195.org/2013_en/info/news/111';
tok2013.linkx = 'http://www.wunderground.com/history/airport/RJTT/2013/2/24/DailyHistory.html';
tok2013.blurb = 'Tokyo Marathon February 24, 2013';

races.tok2013 = tok2013;



%% Cull Useful Data
%find all the specific races in the races object
Araces = fieldnames(races,'-full');

%specify which fields will be used for plotting
syDim = 'wtime'; %y data
sxDim = 'tempavg'; %x data
sCblurb = 'blurb'; %a blurb about the data
sClink = 'linky'; %y data link
sClinkx = 'linkx'; %x data link


%find all the races that have the required fields
datapoints = {sxDim;syDim;sCblurb;sClink;sClinkx};
incRace = ones(numel(Araces),1);
winner = [];
for iRaces = 1:numel(Araces)
    winner = true;
    sDPs = fieldnames(races.(Araces{iRaces}),'-full');
    for iDP = 1:numel(datapoints)
        if sum(strcmp(datapoints(iDP),sDPs))==0
            %if a specific race doesn't have one of the required fields, it
            %is omitted
           winner = false;         
        end        
    end
    incRace(iRaces) = winner;
end
incRace = logical(incRace);
%create a list of races that have all the data points I'm plotting
includeRaces = Araces(incRace);

%create objects and matrices of data I will pass to AttributedPlotHtml()
Dim2Data = zeros(numel(includeRaces),2);
blurbs = cell(numel(includeRaces),1);
links = blurbs;
linksx = blurbs;

%populate objects and matrices with race data
for iDim = 1:length(Dim2Data) 
    Dim2Data(iDim,2) = mod(races.(includeRaces{iDim}).(syDim),1)*24;
    Dim2Data(iDim,1) = races.(includeRaces{iDim}).(sxDim);
    blurbs{iDim} = races.(includeRaces{iDim}).(sCblurb);
    links{iDim} = races.(includeRaces{iDim}).(sClink);
    linksx{iDim} = races.(includeRaces{iDim}).(sClinkx);
end


%fill in Crux object
ImageName = 'RaceTemp';
Crux.blurbs = blurbs;
Crux.links = links;
Crux.linksx = linksx;
Crux.ylab = 'Time [hours]';
Crux.xlab = 'Temp [F]';
Crux.title = ['Avg Race Day Temp vs Women','''s Marathon Race Time'];
Crux.slinkFormat = '%0.2f';
Crux.slinkxFormat = '%0.0f';

AttributedPlotHtml(Dim2Data,ImageName,Crux)

%  %% Example of a different plot function
%        yyunc = 0.3.*ones(numel(includeRaces),1);
%        Crux.plotfun = @(xx,yy) errorbar(xx(:),yy(:),yyunc,'.');

%% Make Attributed HTML
% Syntax:  AttributedPlotHtml(Dim2Data,ImageName,Crux)
%
% Required Inputs:
%    Dim2Data - Two-dimensional matrix with data to be plotted
%               column 1 - x-axis
%               column 2 - y-axis
%
% Optional Inputs:
%    ImageName - String - title to be used for final image and htmlfile
%    Crux - Object - contains properties that are used for attribution and
%                    style
%
%    Recommended Crux Properties:
%       Crux.blurbs - Array of strings with length equal to Dim2Data,
%                   - brief description of data source
%       Crux.links - Array of strings with length equal to Dim2Data,
%                  - link to source of form: "http://www.google.com/"
%       Crux.xlab - string with label for x-axis data
%       Crux.ylab - string with label for y-axis data
%       Crux.imagewidth - number - width of image in inches (rec:5)
%       Crux.imageheight - number - height of image in inches (rec:3)
%    Optional Crux Properties:
%       Crux.plottitle - string title for plot
%       Crux.title - string title for page
%       Crux.linksy - Array of strings with length equal to Dim2Data,
%                  - link to source of x data (if different than y)
%                  - of form: "http://www.google.com/"
%       Crux.slinkFormat - string for sprintf to represent y data magnitude
%                        - ex: '%0.0f' for '54' output from 54.367 input
%                        - ex: '%0.2f' for '54.36' output from 54.367 input
%       Crux.slinkxFormat - string for sprintf to represent x data magnitude
%       Crux.plotfun - anonymous function that defines plot
%                    - see     help function_handle      for use syntax
%                    - must have only two inputs, xdata and ydata


Contact us