How can I make my 'x' matrix in scatterplot in 2 different colors??
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Zhou Ci
 el 2 de Feb. de 2023
  
    
    
    
    
    Comentada: Walter Roberson
      
      
 el 3 de Feb. de 2023
            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. 

0 comentarios
Respuesta aceptada
  Arif Hoq
      
 el 2 de Feb. de 2023
        
      Editada: Arif Hoq
      
 el 2 de Feb. de 2023
  
      temp=[-37; -19; -24; -14];
bin1=[0.0416;0.046667;0.044463;0.024943];
bin2=[0.107853;0.120159;0.114775;0.063871];
bin3=[0.071318;0.078653;0.075131;0.042547];
% bin1 plot
scatter(bin1,temp,'o','filled')
hold on
plot(bin1,temp,'ro','MarkerFaceColor','r')
% bin2 and bin3 plot
scatter([bin2 bin3], temp,'o','filled')
hold on
plot([bin2 bin3], temp,'go','MarkerFaceColor','g')
0 comentarios
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.
0 comentarios
  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()
Ver también
Categorías
				Más información sobre Scatter 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!



