How can I let Matlab automatically insert line breaks in my legend when specifying a legend width?
4 views (last 30 days)
Show older comments
Hi, I am creating a GUI in which a figure is created with a plot with multiple lines, of which each line represents a dataset with a name specified by the input of the GUI.
I want to add a legend at the right of my plot with the full name of every line. I then try to set the legend position so, that it just fits inside the figure window. handles.datanames is a cell containing 1 name of a dataset per element.
h_legend = legend(handles.axes, handles.datanames);
set(h_legend, 'Interpreter', 'none');
set(h_legend, 'units','normalized', 'position',[0.75 0.11 0.07 0.5]);
However, when one of the user specified names is longer than fits inside a legend line, the legend automatically stretches outside the figure window along with the name, instead of using a line break.
I know that I can manually insert a line break with /n, but how, if possible, can I let Matlab do this automatically at the end of the legend box?
Thanks,
Max
0 Comments
Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!