Monday, March 05, 2007

[Matlab] Plotyy and the Labeling

Source:

Matlab Help

Codes:

MY_XLABEL = 'This is xlabel';
MY_Y1LABEL = 'This is y1 label';
MY_Y2LABEL = 'This is y2 label';
MY_Y1LEGEND = {'y1_lg1', 'y1_lg2' };
MY_Y2LEGEND = {'y2_lg1', 'y2_lg2' };
MY_TITLE = 'This is my title';

[AX,H1,H2] = plotyy(x1, y1, x2, y2);
xlabel( MY_XLABEL );
set(get(AX(1),'Ylabel'),'String', MY_Y1LABEL );
set(get(AX(2),'Ylabel'),'String', MY_Y2LABEL );
legend(H1, MY_Y1LEGEND, 'Location', 'NorthWest' );
legend(H2, MY_Y2LEGEND, 'Location', 'NorthEast' );
title( MY_TITLE );

3 comments:

Anonymous said...

uh, that doesn't work for me. I only see one legend. and legend complains about the extra entries in the cellstr...

YYC said...

I just tested the codes and it works in my Matlab 7.1 (SP3). How about posting part of your codes as well as the error message?

I do notice that if I don't specify the locations of the legends, the two legends will appear at the same location (on top of each other).

Anonymous said...

Good brief and this mail helped me alot in my college assignement. Gratefulness you on your information.