color of line plot with marker problem

26 vues (au cours des 30 derniers jours)
Yu Li
Yu Li le 11 Déc 2018
Commenté : Yu Li le 11 Déc 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

Réponse acceptée

Adam Danz
Adam Danz le 11 Déc 2018
Modifié(e) : Adam Danz le 11 Déc 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 commentaire
Yu Li
Yu Li le 11 Déc 2018
Thank you very much,the problem has been solved.

Connectez-vous pour commenter.

Plus de réponses (2)

Saurabh Kotian
Saurabh Kotian le 11 Déc 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 commentaire
Yu Li
Yu Li le 11 Déc 2018
Thank you very much, your answer also works.

Connectez-vous pour commenter.


GT
GT le 11 Déc 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.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by