user interface - Resizeable Legend in Matlab GUI or Legend Scroll Bar -


in matlab have gui analyses , plots data on plot in main figure of gui. have plot lot of different data sets though , have 2 main problems:

  1. i cannot set fixed size area legend constructed in
  2. i cannot work out how make legend text , box scale when gui full screened

one solution thinking scroll bar in legend, possible? image below highlights problem:

http://i42.tinypic.com/6yyzrl.jpg

here solution scale legend whatever scaling factor desire:

close all;  % generate data n = 10; t = 10; x = rand(t, n);  % how scale xlegscale = 0.5; ylegscale = 0.5;  % plot data labels = arrayfun(@(n){sprintf('legend entry line %i', n)}, 1:n); plot(x, 'linewidth', 2); hleg = legend(labels);  % figure out new legend width / height, including little fudge legpos = get(hleg, 'position'); widthfudgefactor = 0.1; legposnew = legpos; legposnew(3:4) = legposnew(3:4) .* [xlegscale ylegscale]; legposnew(3) = legposnew(3) * (1 + widthfudgefactor);  % create new axes matches legend axes , copy legend % children it, delete legend axnew = axes('parent', gcf); xlim(axnew, get(hleg, 'xlim')); ylim(axnew, get(hleg, 'ylim')); box(axnew, 'on'); set(axnew, 'position', legposnew); set(axnew, 'xtick', [], 'ytick', []); copyobj(get(hleg, 'children'), axnew) delete(hleg); hleg = axnew;  % find text objects inside legend hlegtexts = findobj('parent', hleg, 'type', 'text');  % scale font size legtextfontsize = get(hlegtexts, 'fontsize'); fszscale = mean([xlegscale ylegscale]); legtextfontsizenew = cellfun(@(x){fszscale * x}, legtextfontsize); arrayfun(@(h, fontsize)set(h, 'fontsize', fontsize{:}), hlegtexts, legtextfontsizenew); 

this code creates new axes facsimile of original legend axes , position setting work on that. reason legend object doesn't being resized smaller thinks should (presumably there code doing when resizes, there no resizefcn property axes objects, can't see way disable functionality aside making copy of axes).

the thing inside axes need scale font size: rest scaled automatically due use of normalized units.

if kind of scaling solution doesn't tickle fancy, similar (copy legend axes children) add scrollbar new axes (and set units other normalized doesn't scale contents when resize it). might draw inspiration how scrolling this question.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -