2011-12-22 13 views
6

Im affrontato con un problema in cui ho bisogno di tracciare un dato bidimensionale con colori e marcatori diversi.Come stampare dati 2D con colori e marcatori diversi

Ci sono indicati con 2 matrice, cioè punti (n x 2 dimensione) e Label (n x 1 dimensione). Non sono sicuro del numero di valori univoci nell'arrayEtichetta ma il massimo potrebbe essere 10. Vorrei tracciare i punti con colori e indicatori diversi in base al valore Etichetta corrispondente.

uno può aiutare in questo senso

+2

possibile duplicato del [dispersione condizionale in MATLAB] (http://stackoverflow.com/questions/8533136/conditional-scatter-in-matlab) – yuk

risposta

10

Usa gscatter, che fa un grafico a dispersione, con un gruppo (Label nel tuo caso) per tracciare in diversi colori/responsabili.

GSCATTER(X,Y,G,CLR,SYM,SIZ) specifies the colors, markers, and 
    size to use. CLR is either a string of color specifications or 
    a three-column matrix of color specifications. SYM is a string 
    of marker specifications. Type "help plot" for more information. 
    For example, if SYM='o+x', the first group will be plotted with a 
    circle, the second with plus, and the third with x. SIZ is a 
    marker size to use for all plots. By default, the marker is '.'. 

Quindi è possibile specificare i colori come il 'rgcmykwb' da fare rossa per il primo gruppo, verde per il secondo, ecc o [] solo per avere Matlab sorta fuori.

Per impostazione predefinita, Matlab utilizza lo stesso indicatore per ciascun gruppo, pertanto è necessario specificare quali marker si desidera utilizzare per ciascun gruppo. Se fai '.ox+*sdv^<>ph', ti basta scorrere lungo tutti i marker che Matlab ha.

n=50; 
% make nx2 matrix of random points. 
points = random('unif',0,1,n,2); 
% make nx1 matrix of random labels from {1,2,...,5} 
labels=round(random('unif',1,5,n,1)); 

% plot. Let Matlab sort out the colours and we will specify markers. 
gscatter(points(:,1),points(:,2),labels,[],'ox+*sdv^<>ph.') 

sembra un po 'come questo: enter image description here

Problemi correlati