color of line plot with marker problem

조회 수: 26 (최근 30일)
Yu Li
Yu Li 2018년 12월 11일
댓글: Yu Li 2018년 12월 11일
I want to draw a line plot with color, and find the solution here:
the problem is that, it can only control the color of the marker, not the line. I tried to improve the command from:
x = linspace(0,10,50);
y = sin(x);
plot(x,y,'-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
to:
x = linspace(0,10,50);
y = sin(x);
plot(x,y,'r','-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
Matlab reports error.
is there anyway to control the color of both the line and marker together?
Thanks!
Yu

채택된 답변

Adam Danz
Adam Danz 2018년 12월 11일
편집: Adam Danz 2018년 12월 11일
The color of the line is controlled by the 'color' parameter.
x = linspace(0,10,50);
y = sin(x);
plot(x,y,'-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6], 'color' 'r') % 'color' added
  댓글 수: 1
Yu Li
Yu Li 2018년 12월 11일
Thank you very much,the problem has been solved.

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

추가 답변 (2개)

Saurabh Kotian
Saurabh Kotian 2018년 12월 11일
You can set the line color after you plot it.
x = linspace(0,10,50);
y = sin(x);
h = plot(x,y,'-s','MarkerSize',10,...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
set(h,'Color','g');
  댓글 수: 1
Yu Li
Yu Li 2018년 12월 11일
Thank you very much, your answer also works.

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


GT
GT 2018년 12월 11일
There are a couple of ways to solve this (I am using R2018b):
plot(x,y,'-s','MarkerSize',10,'Color','red',...
'MarkerEdgeColor','red',...
'MarkerFaceColor',[1 .6 .6])
Or if you prefer you can:
myhandle = plot(x,y)
And then use the myhandle to change the properties accordingly.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by