How to make the negative sign in the legend easier to see?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I generated the following legend in my plot but the negative sign ('-') is hard to see. I tried several different fonts but it didn't make a big difference. Is there any way to make it look better? For example, I'd like to make the negative sign "longer" and also get some space between "=" sign and the numbers.
The corresponding part of my code looks like this:
for idx = 1:length(sigma_d_list)
sigma_d = sigma_d_list(idx)
plot(x, y); hold on;
Legends{idx} = strcat('\delta_{d} = ', ' ', num2str(sigma_d*1e3), ' mm');
end
xlabel('u (m)'); ylabel('PSF');
xlim([-0.5 0.5]*1e-4);
lgnd = legend(Legends);
set(lgnd, 'FontSize', 14);
set(lgnd, 'FontName', 'Times New Roman');
0 Kommentare
Akzeptierte Antwort
Jan
am 20 Okt. 2021
Bearbeitet: Jan
am 20 Okt. 2021
strcat removes interior spaces. This is not useful here and it is not in general. I consider this as a design error.
Use cat instead:
Legends{idx} = cat(2, '\delta_{d} = ', ' ', num2str(sigma_d*1e3), ' mm');
% or
Legends{idx} = ['\delta_{d} = ', ' ', num2str(sigma_d*1e3), ' mm'];
Do you really want 3 spaces? Or was this a try to struggle with the smart deblanking of strcat?
I'm not a fan of num2str also, which calls sprintf internally. Just call it directly:
Legends{idx} = sprintf('\\delta_{d} = %g mm', sigma_d * 1e3);
Nicer, faster and less confusing.
5 Kommentare
Weitere Antworten (1)
Voss
am 20 Okt. 2021
You can get some more space by using cell arrays in strcat (because strcat trims white space off the ends of character arrays):
Legends{idx} = strcat({'\delta_{d} = '}, {' '}, num2str(sigma_d*1e3), ' mm');
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!