How to show the legends of this plot?

조회 수: 1 (최근 30일)
shdotcom shdotcom
shdotcom shdotcom 2019년 6월 19일
댓글: Shubham Gupta 2019년 6월 20일
How to change the leg1 to show star shape instead of line and how to move the legend to the middle of the figure? Also, the size of first two subplots should be similar to the last one.
Style1 = {'Color',[.8 0.4 0.2], ...
'LineWidth', 0.5,...
'MarkerEdgeColor', [.8 0.4 0.2],...
'MarkerFaceColor', [1 .6 0.2],...
'MarkerSize',1};
Style2 = {'kp--', ...
'LineWidth', 1.5,...
'MarkerEdgeColor', 'k',...
'MarkerFaceColor', 'k',...
'MarkerSize',7};
data =[0.122064975256057 0.215366894811250 0.159333171556989 0.0976468081485719 0.236059851927870;
0.205871594484477 0.0770886614113697 0.249600928022347 0.152967104678426 0.235928630850576;
0.149471800123290 0.124929178221162 0.0592412675482443 0.0363058152312784 0.166172595921666;
0.143565801676485 0.577034235357949 0.0342604280634942 0.0209963902275516 0.254305505440671;
0.0438960965137379 0.110360742437975 0.455810227904852 0.279341793309264 0.0701627705970265;
0.0882928093637788 0.0687946256576963 0.597582437073848 0.0654044123237148 0.492494449718615;
0.103651703284967 0 0.192666230596453 0.0812907926985758 0.141912947586365;
0.0932000919275309 0.370567548504390 0.0272186936686879 0.0114842605146606 0.524579284866712;
0.824750258115474 0.274306217790576 1.09708482973096 0.462888048363850 1.55111177553142;
1.25472714675355 1.25483063048286 0.709096674859205 1.37495226941919 0.0780489150156078]
A = repmat(0.25, 1, 10);
sp = 1;
plotthisnGen=[1 150 300];
set(gcf, 'Position', [100 200 1000 400]);
for nGen=plotthisnGen
subplot(1,3,sp);
parallelcoords(data',Style1{:});
hold on
plot(A, Style2{:});
sp = sp + 1;
end
legend_str = {'leg1','leg2'}
legend(legend_str{1},legend_str{2}, 'Fontsize',10,'Location', 'southoutside', 'Orientation','horizontal');
mat1.JPG

채택된 답변

Walter Roberson
Walter Roberson 2019년 6월 19일
Record the handles of the objects you are going to produce legend() entries for. Pass those handles to legend() as the first parameter. This will prevent legend from looking for graphics objects and will always use the exact order of the handles that you pass in.
  댓글 수: 1
Shubham Gupta
Shubham Gupta 2019년 6월 20일
This helped me to understand the legend() a lot more better. Thanks !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Shubham Gupta
Shubham Gupta 2019년 6월 19일
  • You can change the order of plots to assign the legend as required. So, if you want leg1 to show 1st line then you should plot it before others. For loop can be replaced by:
for nGen=plotthisnGen
subplot(1,3,sp);
hold on
plot(A, Style2{:});
parallelcoords(data',Style1{:});
sp = sp + 1;
end
  • To keep the plots of same size you can define the location of the legend to be inside the plotting area so MATLAB doesn't adjust the size of the subplot :
legend(legend_str{1},legend_str{2}, 'Fontsize',10,'Location', 'North', 'Orientation','horizontal');
  • This one is little hard to understand but if you want legend to show in the middle of the Figure then you just put legend in the 2nd subplot since it is already in the middle. So, last line should be replaced by:
subplot(132)
legend(legend_str{1},legend_str{2}, 'Fontsize',10,'Location', 'North', 'Orientation','horizontal');
I hope it helps!
  댓글 수: 1
shdotcom shdotcom
shdotcom shdotcom 2019년 6월 19일
Thank you for your answer, in this code I need A to be ploted after data.
for nGen=plotthisnGen
subplot(1,3,sp);
hold on
plot(A, Style2{:});
parallelcoords(data',Style1{:});
sp = sp + 1;
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by