Skip to content

Instantly share code, notes, and snippets.

@seankross
Last active April 15, 2024 15:32
Show Gist options
  • Save seankross/48de284fd35e101d4e9ce8b29d2da0fa to your computer and use it in GitHub Desktop.
Save seankross/48de284fd35e101d4e9ce8b29d2da0fa to your computer and use it in GitHub Desktop.
function colors = pal_hue(n, s, v)
% Generates a palette of n evenly spaced colors with default settings
% similar to R's scales::pal_hue().
% s is the saturation (default 0.75), v is the value (brightness, default 0.95).
% The hue component varies from 0 to 1.
if nargin < 2
s = 0.75; % Default saturation
end
if nargin < 3
v = 0.95; % Default value
end
hues = linspace(0, 1, n+1);
hues(end) = []; % Exclude the last element to avoid repeating the first color
colors = hsv2rgb([hues', s * ones(n, 1), v * ones(n, 1)]);
end
% colors = pal_hue(6); % Uses default saturation and value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment