How to make the negative sign in the legend easier to see?
8 ビュー (過去 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');
0 件のコメント
採用された回答
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.
その他の回答 (1 件)
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 Center および File Exchange で Labels and Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!