color of line plot with marker problem

26 visualizaciones (últimos 30 días)
Yu Li
Yu Li el 11 de Dic. de 2018
Comentada: Yu Li el 11 de Dic. de 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

Respuesta aceptada

Adam Danz
Adam Danz el 11 de Dic. de 2018
Editada: Adam Danz el 11 de Dic. de 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 comentario
Yu Li
Yu Li el 11 de Dic. de 2018
Thank you very much,the problem has been solved.

Iniciar sesión para comentar.

Más respuestas (2)

Saurabh Kotian
Saurabh Kotian el 11 de Dic. de 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 comentario
Yu Li
Yu Li el 11 de Dic. de 2018
Thank you very much, your answer also works.

Iniciar sesión para comentar.


GT
GT el 11 de Dic. de 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.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by