Move line in legend
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Janak Thotakura
2017년 10월 13일
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.
For more information refer to this link https://www.mathworks.com/help/releases/R2017a/matlab/ref/legend.html
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!