Plot, legend, settings, appearance

조회 수: 1 (최근 30일)
Ionut  Anghel
Ionut Anghel 2015년 7월 8일
댓글: Star Strider 2015년 7월 9일
Hi, I have following question: This question is about a plot as in the image bellow.
clear all;
close all;
x=(1:1:50);
y=x.^2;
plot(x,y,'-b');
hold on;
plot(x(1:5:end),y(1:5:end),'bo');
legend('data','Location', 'northeast');
Because the points are very close each other and I have multiple graphs I have to use markers. The problem is that I would like to have a legend showing not (data and data 2) but let say (data) which it combines both the marker and the line. Can be somehow overwritten the actual legend or create other new? Thank you
<<
>>

채택된 답변

Star Strider
Star Strider 2015년 7월 8일
편집: Star Strider 2015년 7월 8일
If I understand correctly what you want to do, change this plot call:
plot(x, y,'-b');
hold on;
plot(x(1:5:end),y(1:5:end),'bo');
to simply:
plot(x, y, '-ob')
—————————————————————————————————————
EDIT: Changed to reflect ‘x’ and ‘y’ now appearing on both plot calls in the original Question.
  댓글 수: 4
Ionut  Anghel
Ionut Anghel 2015년 7월 9일
Your solution is working very nice. Based on your code I create a function in a script which generates 200 figures with the desired legend. Thank you very much. I acceepted your previous answer because I cannot see how to accept your second answer. Best wishes.
Star Strider
Star Strider 2015년 7월 9일
My pleasure.
I only submitted one Answer, so you accepted it and all subsequent Comments. (Thank you!) This is how MATLAB Answers works, so you did it correctly. Sometimes it requires a few iterations to understand the problem and post a correct solution.

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

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