MATLAB: How to remove the border surrounding the legend box in MATLAB

borderboxlegendMATLAB

I would like to remove the border surrounding the legend box in MATLAB.

Best Answer

The following example demonstrates how to remove the legend border and legend background for MATLAB 5.3 (R11):
plot(rand(10,10)); % Generate a plot.

legend('a1', 'a2','a3','a4','a5','a6','a7','a8','a9','a10') % Add a legend

h = findobj('type', 'axes'); % Find all sets of axes
set(h(1), 'visible', 'off') % Hides the legend's axes (legend border and background)

The following example demonstrates how to remove the legend border and legend background for MATLAB 6.0 (R12) and later versions:
plot(rand(10,10)); % Generate a plot.
legend('a1', 'a2','a3','a4','a5','a6','a7','a8','a9','a10') % Add a legend
legend boxoff % Hides the legend's axes (legend border and background)