How to make the negative sign in the legend easier to see?

14 次查看(过去 30 天)
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');

采纳的回答

Jan
Jan 2021-10-20
编辑:Jan 2021-10-20
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 个评论
Daigo
Daigo 2021-10-21
@Bruno Luong Aha, you can set such a fine-grained font format! Thanks for your tip!

请先登录,再进行评论。

更多回答(1 个)

Voss
Voss 2021-10-20
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');

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by