How does one Increase spacing between different entries in a plot legend?
Mostra commenti meno recenti

If you look at the legend on the left it's hard to tell when one legend entry ends and the next begins. The spacing on the right is a bit too extreme, but hopefully you get the idea. I want to learn how to insert a line break between different legend entries.
There's already a posting with a title similair to this (click here). However, The person was trying to embed their plot in a Latex document, and I'm not doing anything like that. Also their code contains a lot of dollar signs and things I don't understand. Here's my code:
line_handles = [h1, h2, h3, h3];
t1 = 'Previously localized sensors';
t2 = ['Previously localized sensors', sprintf('\n'),...
'being used to locate the next sensor'];
t3 = ['Sensors of unknown location'];
t4 = ['Sensor whose location we' sprintf('\n') 'are presently determining'];
legend_texts = {t1, t2, t3, t4};
h_leg = legend(line_handles, legend_texts);
legend(h_axes,'boxon');
legend(h_axes,'show');
h_leg.FontSize = 22.5;
h_leg.Location = 'bestoutside';
The reason I passed handles of chart line objects to the legend function is that I don't want a legend entry for every chart line object which is being plotted. I only want entries in the legend for four out of many data series which are in this plot.
The following change doesn't affect the spacing at all:
t1 = ['text' sprintf('\n') ' ' sprintf('\n')...
' ' sprintf('\n') ' ' sprintf('\n')...
' ' sprintf('\n') ' '];
2 Commenti
Sam Muldoon
il 7 Dic 2015
Modificato: Sam Muldoon
il 7 Dic 2015
Walter Roberson
il 7 Dic 2015
Testing in R2014a (before the change to the graphics system) it appears that if you use a trailing non-printable character like \h then spacing is introduced, but the sample icon will be centered on all of the lines considered to be present.
I do not know the capabilities with legend from R2014b onward.
Risposta accettata
Più risposte (1)
Arun Krishnadas
il 22 Lug 2020
0 voti
A simple method would be to add \newline in a new line on each legend entry, which worked in one case for me.
Categorie
Scopri di più su Legend in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
