How do we define the colors in the MarkerFaceColor for the plots containing lines and points?
133 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am plotting a graph where I have nine speakers (see the attached). I am not sure why the color of S8_M is the same as S1_F, and S9_F is the same as S2_F. This is confusing as we can't differentiate the speakers' data. May I know how to define the colors and not use the default settings? Or where am I doing wrong? Any suggestions will be appreciated. Part of the code is given below:
ax(1)=subplot(1,2,1);
h1 = plot(x1*100, y1, '-o');
set(h1, {'MarkerFaceColor'}, get(h1,'Color'));
axis padded
grid;
xlabel('Time points (%)');
ylabel('f0 (Hz)');
title('beer');
linkaxes(ax,'y')
ax(2) =subplot(1,2,2);
h2 = plot(x2*100, y2, '-o');
set(h2, {'MarkerFaceColor'}, get(h2,'Color'));
title('north');
axis padded
grid;
0 comentarios
Respuesta aceptada
Voss
el 2 de Abr. de 2022
Editada: Voss
el 2 de Abr. de 2022
Inspect either of the properties shown here:
get(0,'DefaultAxesColorOrder') % default line colors for any axes
figure('Visible','off');
get(gca(),'ColorOrder') % this particular axes' line colors (same as above by default)
You see there are 7 colors defined (7 rows of RGB values). MATLAB cycles through these colors when you use plot and other high-level plotting functions. Since there are 7 colors there and you plot 9 lines, the last two lines get the same colors as the first two, as you observe.
There are different ways to go about changing this. One way is to change one or both of the above settings:
% add grey and black to the default set of colors for any axes:
default_colors = get(0,'DefaultAxesColorOrder');
set(0,'DefaultAxesColorOrder',[default_colors; 0.5 0.5 0.5; 0 0 0]);
% or add grey and black to the set of colors for this axes only:
default_colors = get(gca(),'ColorOrder');
set(gca(),'ColorOrder',[default_colors; 0.5 0.5 0.5; 0 0 0]);
Then use plot like before:
set(gcf(),'Visible','on');
for ii = 1:9
plot(1:10,-ii+(1:10)); % using color order with 9 colors now, last two are grey and black
hold on
end
legend();
Or you can explicitly specify each color when you plot, without changing those settings:
figure();
colors = rand(12,3); % 12 random colors, you can specify the colors you want here
for ii = 1:size(colors,1)
plot(1:10,-ii+(1:10),'Color',colors(ii,:));
hold on
end
legend();
4 comentarios
Más respuestas (0)
Ver también
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!