File Exchange Pick of the Week

Our best user submissions

Easy labeling of a figure or axes

Brett's Pick this week is "Bordertext", by Jan de Wilde.

With "bordertext," Jan has shared an elegant way to label a figure or an axes, saving us the trouble of having to calculate positions for our text. The function takes as an input a string indicating where you want your text. Thus, simply by specifying 'top,' 'bottom,' 'left,', 'right,' 'center', or 'userdefined,' you can position even multiline strings automatically, with respect to the current axes.

Moreover, you can modify those input strings with the prefix 'inner' (in the cases where it makes sense to do so) to make them refer to the interior of your axes, or with 'figure' to make them refer to figure positions. For instance:

modOpts = {'','inner','figure'};
mainOpts = {'topleft','top','topright','right',...
   'rightbottom','bottom','bottomleft','left','lefttop','center'};
colors = jet(32);
for ii = 1:15
    color = colors(randi(size(colors,1)),:);
    modOpt = modOpts{randi(numel(modOpts),1)};
    mainOpt = mainOpts{randi(numel(mainOpts),1)};
    if strcmp(mainOpt,'center'),modOpt = '';end
    option = [modOpt,mainOpt];
    bordertext(option,option,...
        'Color',color,'BackgroundColor',imcomplement(color), ...
        'FontSize',18);
    pause(1.5)
    bordertext(option,'');
end

Additionally, one can specify a host of formatting commands to control the style of the text.

Jan's code is very nicely written and documented. Plus, I like that he was responsive to a comment requesting support for "standard [MATLAB] syntax." (I garner that the file originally required format strings to be specified in a non-standard fashion. That format option is still available, and convenient, but I agree with the commenter that the standard format is easier to use.)

As always, I welcome your thoughts and comments. Or leave feedback for Jan here.




Published with MATLAB® R2013a

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.