How to make the negative sign in the legend easier to see?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Jan
el 20 de Oct. de 2021
Editada: Jan
el 20 de Oct. de 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 comentarios
Más respuestas (1)
Voss
el 20 de Oct. de 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');
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!