I used the below code and got error with the legend as in the figure. Can someone please help fix?
fig = figure(1);
ax = axes(fig);
xlabel('\xi');
ylabel(' \Omega(\xi,\tau)');
title('Varying injection rates vs fracture width');
hold on
legend('\alpha=0,k-','\alpha=1/9,b-','\alpha=1/10,r-','location', 'northeast')
h1 = openfig('widthchange.fig','reuse');
h2 = openfig('widthconstant.fig','reuse');
h3 = openfig('widthchange2.fig','reuse');
copyobj(h1.Children.Children,ax);
copyobj(h2.Children.Children,ax);
copyobj(h3.Children.Children,ax);
close(h1);
close(h2);
close(h3);

댓글 수: 3

VBBV
VBBV 2020년 10월 2일
편집: VBBV 2020년 10월 2일
%if true
% code
% end
hold on
legend('\alpha=0','\alpha=1/9','\alpha=1/10','location', 'northeast')
Specify the colors of lines in the plot function. You are trying to specify them in legend
Hai Nguyen
Hai Nguyen 2020년 10월 2일
편집: Hai Nguyen 2020년 10월 2일
I tried as instructed and still got error for the colors. Also, the line colors in the legend are not the same as in the plots. What caused this please?
Adam Danz
Adam Danz 2020년 10월 2일
You don't have 3 lines. You have 6 lines. There are 2 blue, 2 black, and 2 red, in that order.
More detail in my answer below.

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

 채택된 답변

Adam Danz
Adam Danz 2020년 10월 2일
편집: Adam Danz 2020년 10월 2일

0 개 추천

Move this line to end, after copying the line objects.
legend('\alpha=0','\alpha=1/9','\alpha=1/10','location', 'northeast')
Also, it looks like each line is represented twice since your legend contains two lines for each color. Examine the outputs of h1 h2 h3 to see if there is more than 1 handle in each.
If so, and if the lines are identical, use,
legend([h1(1),h2(1),h3(1)], '\alpha=0','\alpha=1/9','\alpha=1/10','location', 'northeast')

추가 답변 (0개)

카테고리

태그

질문:

2020년 10월 2일

댓글:

2020년 10월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by