Legend not matching graph in specific code

조회 수: 5 (최근 30일)
Joshua Martin
Joshua Martin 2020년 4월 14일
댓글: Joshua Martin 2020년 4월 14일
I used previous questions answers to get a template code working however, when I apply this to my real code, it doesn't change and outputs no errors so I am at a loss.
Here is my testing code which works correctly:
x=[0:1:20]
clf
hold on
L1=plot(x,2*x,'r')
L2=plot(x,3*x,'k')
L3=plot(x,4*x)
L4=plot(x,5*x,'k')
L5=plot(x,6*x,'b')
L6=plot(x,7*x,'k')
L7=plot(x,8*x)
L8=plot(x,9*x,'k')
L9=plot(x,10*x,'k')
L10=plot(x,11*x,'k')
L11=plot(x,12*x,'k')
legend([L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11],'2D velocities','6D velocities','10D velocities','Lower Nozzle','Uppper Nozzle','Centre Line','Upper Divergence Line','Lower Divergence Line','Upper Core','Lower Core','FontSize',6,'Location','best')
Here is my real code which doesn't work:
(I cannot provide the real data for it)
hold on
L1=plot(x_core,y_core1,'r');
L2=plot(x_core,y_core2,'r');
L3=plot(5*v_2+2*D,r_2);
L4=plot(5*v_6+6*D,r_6);
L5=plot(5*v_10+10*D,r_10);
L6=plot(x_nozzle,x_nozzle/4-15,'k');
L7=plot(x_nozzle,-x_nozzle/4+15,'k');
L8=plot(cl,cl*0);
L9=plot(div,div*topgrad+topint,'b');
L10=plot(div,div* botgrad+botint,'b');
L11=plot([0 0], ylim, 'k')
hold off
%applies axis labels
legend([L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11],'2D velocities','6D velocities','10D velocities','Lower Nozzle','Uppper Nozzle','Centre Line','Upper Divergence Line','Lower Divergence Line','Upper Core','Lower Core','Origin','FontSize',6,'Location','best')
I can't spot where the difference is.
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 4월 14일
I would have thought that L8=plot(cl,cl*0); would be the Centre line, not L6=plot(x_nozzle,x_nozzle/4-15,'k'); ?
Joshua Martin
Joshua Martin 2020년 4월 14일
Thank you, you are indeed correct the code works correctly now with some further reordering.
To clarify, my issue was that I was not seeing the correct pairs of colours, it just showed a rainbow from my perspective. By reordering them correctly, I realised that it did indeed show the colours just whilst zoomed out, the pair of reds looks like red and orange, and likewise for the blue and black sets. Hence the confusion.
Thank you again.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by