How do I remove data points off legend

조회 수: 14 (최근 30일)
Harry Spratt
Harry Spratt 2019년 12월 18일
댓글: Harry Spratt 2019년 12월 18일
Just wondering how i get rid of the data point off the graph shown. Any help is much appreciated.
x_1 = [0 1 2 3];
y_1 = [0.031 0.2236 0.431 0.578];
errx_1 = 0.1*ones(size(x_1));
erry_1 = 0.001*ones(size(x_1));
errorbar(x_1,y_1,erry_1,erry_1,errx_1,errx_1,'b*')
hold on
plot(fittedmodel1)
hold on
x_2 = [4 5 6 7 8 9 10];
y_2 = [0.645 0.684 0.711 0.731 0.749 0.765 0.779];
errx_2 = 0.1*ones(size(x_2));
erry_2 = 0.001*ones(size(x_2));
errorbar(x_2,y_2,erry_2,erry_2,errx_2,errx_2,'b*')
hold on
plot(fittedmodel2,'m')
legend({'','cos(2x)','','son(t)'},'Location','southeast')
xlim([0 10])
ylim([0 0.8])
Help.jpg

채택된 답변

Adam Danz
Adam Danz 2019년 12월 18일
편집: Adam Danz 2019년 12월 18일
Specify the line objects to include in the legend by supplying their handles.
h1 = plot(fittedmodel1);
h2 = plot(fittedmodel2,'m');
legend([h1,h2],{'cos(2x)','son(t)'},'Location','southeast')
Do you mean sin(t)?
  댓글 수: 3
Adam Danz
Adam Danz 2019년 12월 18일
Glad I could help. Be aware that if you add additional objects to the axes after calling legend() they will be added to the legend.
Harry Spratt
Harry Spratt 2019년 12월 18일
Ok I will bear that in mind. Thanks!

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

추가 답변 (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