How can I make my 'x' matrix in scatterplot in 2 different colors??
Mostrar comentarios más antiguos
Hello everyone,
I am trying to make a scatterplot of below data. Where temp should be on y-axis and rest of the five bins on x-axis. Regarding x-axis, I want 2nd column (Bin 1) to be in a different color and rest of the 4 bins in another color. I can't figure out how to do this. Any help would be highly appreciated. Thank you.

Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 2 de Feb. de 2023
A different approach would be to use gscatter
xdata = repmat(Temp, 5, 1);
ydata = [Bin1; Bin2; Bin3; Bin4; Bin5];
g = 2 * ones(size(ydata)); %everything is group 2
g(1:numel(Bin1)) = 1; %except initial data
gscatter(xdata, ydata, g)
In this particular case it is probably easier to handle things the way that @Arif Hoq suggested... but gscatter() is an option that sometimes makes a lot of sense to use.
Walter Roberson
el 2 de Feb. de 2023
scatter() can take information about color in the 4th parameter. The color information can be set per-point.
xdata = repmat(Temp, 5, 1);
ydata = [Bin1; Bin2; Bin3; Bin4; Bin5];
g = 2 * ones(size(ydata)); %everything is group 2
g(1:numel(Bin1)) = 1; %except initial data
pointsize = [];
scatter(xdata, ydata, pointsize, g);
1 comentario
Walter Roberson
el 3 de Feb. de 2023
Current versions of scatter would also support
h = scatter(Temp, [Bin1, Bin2, Bin3, Bin4,Bin5]);
h(1).CData = [1 0 0]; %red, must be rgb in this context
set(h(2:end), 'CData', [0 1 0]); %green, must be rgb in this context
When you scatter() with multiple columns in a 2D array, each column becomes its own scatter() handle. Setting a property of a single handle such as h(1).CData can be done with assignment format, but setting the properties of multiple handles at the same time such as h(2:end) CData requires using set()
Categorías
Más información sobre Scatter Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
