MATLAB Answers

Move line in legend

조회 수: 16(최근 30일)
JB
JB 11 Oct 2017
I have a cell array with four strings which is used as legend for four individual X,Y plots. One string is very long and therefore devided into a four-line legend by sprntf, The four plot legend is shown in the figure below. Is it possible to move the blue line up so it fits the first line, which is next to the 'Av.'
Here is a short example of code:
X=[2 4 6 8; 2 3 4 5; 4 5 6 7 ; 7 6 8 9];
Y=[1 3 5 7; 2 5 6 8; 8 6 4 2; 7 5 4 3];
Title = {
'123456789_1'
'ABCDEFGHIJ_1'
'123ABC_1'
sprintf('Av. \n(123456789_1 \nABCDEFGHIJ_1 \n123ABC_1)')
};
fig1=figure;
hold on
for i=1:size(X,2)
plot(X(:,i),Y(:,i));
end
hold off
legend(Title,'Orientation','vertical','Location','northeastoutside','FontSize',8);

  댓글 수: 0

로그인 to comment.

답변 수 (1)

Janak Thotakura
Janak Thotakura 13 Oct 2017
To move the line in legend you can change the YData value of the legend line as shown in the below code.
x= 1:5;
y1= 2*x;
y2= 3*x;
Title = { 'legend_1' sprintf('legend_2 \nlegend_3')};
fig1=figure;
hold on
plot(x,y1);
plot(x,y2);
hold off
legend(Title,'Orientation','vertical','Location','northeastoutside','FontSize',8);
fig2=figure;
hold on
plot(x,y1);
plot(x,y2);
hold off
[lgd,icons,plots,txt] = legend(Title,'Orientation','vertical','Location','northeastoutside','FontSize',8);
icons(5).YData = [0.5 0.5];
However, the syntax used for figure 2 legend is not recommended as it creates a legend that does not support all graphics features.

  댓글 수: 0

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그

제품


Translated by