How to Remove an Entry From the Legend on MATLAB

Updated February 21, 2017

MATLAB is an incredibly useful mathematics and engineering software tool capable of performing advanced calculations and engineering simulations. One of its most useful purposes is plotting data into 2D and 3D figures. On graphs with multiple lines or bars of data, a legend is useful to define data series. However, you might not want every data series to appear in the legend. MATLAB does not offer a straightforward way to remove an entry in a legend, but it is possible to do so if you follow a few steps.

Click on the button that looks like a mouse pointer in the figure toolbar to enable editing of the plot.

Click on a data series line or bar to select it.

Go back to MATLAB's command line and type the following:

hasbehavior(gco, 'legend', false);

Return to the figure and right-click on the legend. Click "Refresh," and the legend entry for the line or bar selected in Step 2 will disappear from the legend.

Cite this Article A tool to create a citation to reference this article Cite this Article

About the Author

Joe Friedman began writing in 2008 while in the U.S. Air Force as a KC-10 tanker pilot. He is now an equipment engineer in the semiconductor manufacturing industry. Friedman holds a Bachelor of Science in engineering physics from Embry-Riddle Aeronautical University and a Master of Science in electrical engineering from Drexel University.