Turning the legend box off makes the legend title disappear in Matlab

matlab

Solution

Ok now I understand your problem.

I made up some data:

n = 8;
x = [1:n];
y(:,1) = rand(1,n);
y(:,2) = rand(1,n);

Then used your plotting commands:

h = bar(x,y,'stacked');
hL = legend ((h([1 2])), {'North', 'South'});

But rather than turn off the box, just set the edge color to white:

set(hL, 'EdgeColor', 'w')

And then using:

newPosition = [0.75 0.75 0.1 0.1];
newUnits = 'normalized';
set(hL,'Position', newPosition,'Units', newUnits);
v = get(hL,'title');
set(v,'string','Region','fontsize',9);

I get:

So now the "Region" title doesn't disappear.

Note that I had to change the coordinates of the legend to keep it within the figure, but of course you can place that where you want.

Problem

When I turn the legend `box off`, the legend title disappears. What am I doing wrong? ``` hL = legend ((h([1 2])), {'North', 'South'}); set(hL,'box','off') newPosition = [0.83 0.8 0.1 0.1]; newUnits = 'normalized'; set(hL,'Position', newPosition,'Units', newUnits); v = get(hL,'title'); set(v,'string','Region','fontsize',9); ```

Original source