Scatter Plot following a colormap regulation
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Adi Purwandana
 el 8 de Nov. de 2024
  
    
    
    
    
    Comentada: Star Strider
      
      
 el 8 de Nov. de 2024
            Hello there,
I have a datasets of positions (attached). Here are my intention:
- Make a scatter plot with different color positions, let's say following "jet" colormap.
- Put the station number also along with the scatter plot. Let's say, the value (number of the respected station shown beside the scatter plot of each station.
Here's my code so far which is failed to follow the jet colormap:
clear all;
clc;
A=dir('*.mat');
numprof = length(A);
couleur = jet(numprof); %prefered colormap is jet
for nn=1:length(A)
    filename        = A(nn).name;
    B               = load(filename);
    xp             = B.T.xpos(1);
    yp             = B.T.ypos(1);
    sta             = B.T.station(1); 
    scatter(xp,yp,50,"square",'filled','color',couleur(nn,:), 'DisplayName', string(sta)); % it seems not following the jet colormap setting
    hold on;
end
hlgd = legend('Location','best'); 
title(hlgd, 'Station Number')
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 8 de Nov. de 2024
        
      Editada: Star Strider
      
      
 el 8 de Nov. de 2024
  
      The DisplayName name-value pair will use that information for the legend entry for each plotted pont.  If you want the station number displayed next to each symbol, usee the text function.  
The problem with your original code is that the scatter function syntax is different from other plot-type functions.  Give it the command syntax it is expecting and the colors plot correctly.  
Try this — 
clear all;
clc;
A=dir('*.mat');
numprof = length(A);
couleur = jet(numprof); %prefered colormap is jet
for nn=1:length(A)
    filename        = A(nn).name;
    B               = load(filename);
    xp              = B.T.xpos(1);
    yp              = B.T.ypos(1);
    sta             = B.T.station(1); 
    % scatter(xp,yp,50,"square",'filled','color',couleur(nn,:), 'DisplayName', string(sta)); % it seems not following the jet colormap setting
    scatter(xp,yp,50,couleur(nn,:),"square",'filled', 'DisplayName', string(sta)); % it seems not following the jet colormap setting
    hold on;
end
hlgd = legend('Location','best'); 
title(hlgd, 'Station Number')
axis('padded')
% return
clearvars
mats = dir('*.mat');
for k = 1:numel(mats)
    filename{k,:} = mats(k).name;;
    LD = load(filename{k});
    S{k} = LD.T;
end
filename{:}
% format long
% S{:}
cm = jet(numel(S));
figure
hold on
for k = 1:numel(S)
    scatter(S{k}.xpos(1), S{k}.ypos(1), 200, cm(k,:), 'filled', 's')
    text(S{k}.xpos(1), S{k}.ypos(1), sprintf('  Station %d',S{k}.station(1)), 'Horiz','left', 'Vert','middle')
end
hold off
grid
axis('padded')
xlabel('xpos')
ylabel('ypos')
As with the previous problem, you  can use one loop for this.  I used two loops because I wanted to see what the .mat  fiiles contained, before I proceeded with the plot.  
EDIT — (8 Nov 2024 at 15:53)
Minor tweaks.  
.
2 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Orange 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!


