Why is the text in the legend not aligned properly to its corresponding marker in MATLAB 6.5 (R13)?

7 views (last 30 days)
Why is the text in the legend not aligned properly to its corresponding marker in MATLAB 6.5 (R13)?
I am running the following lines of code:
a = plot([1 2 3 4], [1 2 3 4],'r*');
hold on
b = plot([1 2 3 4], 2*[1 2 3 4],'b+');
c = plot([1 2 3 4], 3*[1 2 3 4],'gx');
legend([a,b,c], 'one','two','three');
The legend that is created is misaligned. The text does not align vertically with the plot figures in the legend. It is a gradual misalignment; the word "one" is aligned, "two" is a little high, and "three" is so high that its baseline would go through the center of the green "x".
I have tried varying the "VerticalAlignment" property but none is any better than "center".
When exporting the figure to an EPS-file, the alignment is still off.
I am using it on Linux (Red Hat). I do not have this problem on Windows.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is a bug in the LEGEND function within MATLAB 6.5 (R13) on Linux. Our development staff is investigating this issue.
Currently, you can try the following to work around this issue:
Manually change the "YDATA" property of the "line object" in the legend. Here is the code that does this:
a = plot([1 2 3 4], [1 2 3 4],'r*');
hold on
b = plot([1 2 3 4], 2*[1 2 3 4],'b+');
c = plot([1 2 3 4], 3*[1 2 3 4],'gx');
hl = legend([a,b,c], 'one','two','three');
hc = get(hl, 'children');
set(hc(1), 'ydata', 0.22) % Centering the third
set(hc(3), 'ydata', 0.53) % Centering the second
The values "hc(1)" and "hc(3)" are the handles to the line object that the markers in the legend consist of. You will have to change the "YDATA" property to align properly. The above numbers seem to work fine.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!