Need data points in 'plot' filled with the same color as the line.
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Christopher Graham
el 9 de Oct. de 2023
Comentada: Vitek Stepien
el 10 de Sept. de 2024
I need the data points in a plot to be the same color as the line.
I tried specifying the line and data points as follows: "o-", "MarkerFaceColor","auto".
The result is a line with unfilled data points. The data points have the outline that is the same color as the line but the data points are not filled.
What am I missing?
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 9 de Oct. de 2023
From the documentation of plot, sub-section MarkerFaceColor - "The "auto" option uses the same color as the Color property of the parent axes."
The color of the parent axes is white, see below -
x = 0:0.1:10;
y = sin(x);
figure
plot(x,y,'o-', 'MarkerFaceColor', 'auto')
get(gca,'Color')
Solution, specify the color -
col = [0 0 1];
figure
plot(x,y,'o-', 'Color', col, 'MarkerFaceColor', col)
or plot the curve first and then set the MarkerFaceColor to be the same as the Line Color via the handle -
figure
h=plot(x,y,'o-');
h.MarkerFaceColor = h.Color;
3 comentarios
Dyuman Joshi
el 10 de Oct. de 2023
You are welcome!
If my answer solved your problem, please consider accepting the answer.
Vitek Stepien
el 10 de Sept. de 2024
I have a follow up question, is there an easy way of doing that if the variable I'm plotting is a 2D matrix, so it plots N different curves with the default colors? I would really hate to have to cycle through all of them in a for loop, manually defining each MarkerFaceColor to match the line color.
Example:
m = magic(4);
figure, tiledlayout(2,1), nexttile
plot(magic(4),'Marker','square','MarkerFaceColor','auto'), title 'This is simple but not what I need'
cmap = colororder();
nexttile, hold on
for N = 1:length(m)
plot(m(:,N),'Marker','square','MarkerFaceColor', cmap(N,:))
end
title 'This is what I want to see'
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Object Properties 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!



