How to assign colors to each value in scatter function - GNU Octave

后端 未结 2 495
说谎
说谎 2020-12-21 18:05

How can I use the scatter function in GNU Octave in order to assign colors to each plotted value ?

2条回答
  •  不思量自难忘°
    2020-12-21 18:46

    Here's a nice illustrative example:

    X = linspace(0, 4 * pi, 100);                       % Create points (100 elements)
    Y = 100 * sin(X); 
    
    S = Y + 100;                                        % Sizes array. All values need 
                                                        % to be larger than 0
    
    C = [linspace(0,1,100); ones(1,100); ones(1,100)]'; % create hsv triplets at full 
                                                        % saturation and value that
                                                        % cover the whole colour 
                                                        % (i.e. hues) spectrum
    
    C = hsv2rgb(C);                                     % convert to rgb triplets; to
                                                        % be used as a 'colour array'
    
    scatter(X,Y,S,C,'filled','MarkerEdgeColor','k');    % fill bubbles, black border
    

提交回复
热议问题