Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

How do I remove the border surrounding the legend box in MATLAB?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-16FH1
Product:   MATLAB
Reported in Release:   R9
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I remove the border surrounding the legend box in MATLAB?

Problem Description:

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

Solution:

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)

Please provide feedback to help us improve this Solution
Contact support