Markers and text in legend appear misaligned

2 ビュー (過去 30 日間)
Benedict Vassileiou
Benedict Vassileiou 2019 年 12 月 21 日
回答済み: Benedict Vassileiou 2020 年 1 月 17 日
Hello everyone.
As you can see below, the legend appears quite strange, when I run the following code on Matlab2018b. Lines and the associated text are completely misaligned. Any ideas what may be going wrong and how I could correct it? I would much appreciate any hints.
Thanks,
Benedict
y = [0.0662 0.0078 0.4142;
0.1952 0.0131 0.0693;
0.0456 0.1563 0.0966];
x = 1:size(y,2);
colours = [0 0 0;
0 0 1;
1 0 0];
linelabels = {'Line1' 'Line2' 'Line3'};
figure;
hold on
clear ax
for i = 1 : size(y,1)
ax(i) = plot(x,y(i,:),'-','Color',colours(i,:));
end
hold off
legend(ax,linelabels);
set(gca,'XTick',x);
  1 件のコメント
Star Strider
Star Strider 2019 年 12 月 21 日
It works correctly for me in R2019b.
What MATLAB release are you using?
What graphics card?
Be sure you have the latest MATLAB update, and the latest graphics drivers.

サインインしてコメントする。

回答 (2 件)

Benedict Vassileiou
Benedict Vassileiou 2020 年 1 月 17 日
Hello everyone and thank you for your feedback.
It turns out that this misalignment is present only when toolboxes like SPM12 and eeglab are added to the matlab paths at the beginning of a matlab session. As these toolboxes implement several graphics functions, it is probably the case that matlab's default graphics settings are altered and, as a result, create such weird figures.
Benedict

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2019 年 12 月 24 日
Hey Benedict!
I tried to reproduce the issue on MATLAB R18b, and am unable to notice any discrepancy. The performance is as expected. As mentioned on this thread, it could potentially be an issue with your graphics card that's creating trouble.
To be sure about this, open MATLAB using -
matlab -softwareopengl
Try running your script again now, do you notice the same issue again?
Hope this helps!

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by