color of line plot with marker problem

26 Ansichten (letzte 30 Tage)
Yu Li
Yu Li am 11 Dez. 2018
Kommentiert: Yu Li am 11 Dez. 2018
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

Akzeptierte Antwort

Adam Danz
Adam Danz am 11 Dez. 2018
Bearbeitet: Adam Danz am 11 Dez. 2018
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 Kommentar
Yu Li
Yu Li am 11 Dez. 2018
Thank you very much,the problem has been solved.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Saurabh Kotian
Saurabh Kotian am 11 Dez. 2018
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 Kommentar
Yu Li
Yu Li am 11 Dez. 2018
Thank you very much, your answer also works.

Melden Sie sich an, um zu kommentieren.


GT
GT am 11 Dez. 2018
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.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by