EquiDistantColorGen​erator

Optimize your colored plots by using colors that have maximum contrast on a white background. Best for plotting in scientific publications.
다운로드 수: 18
업데이트 날짜: 2025/11/13

라이선스 보기

%EQUIDISTANTCOLORGENERATOR Generate visually distinct, equidistant colors.
%
% [ColorMatrix, angleOnPallet] = EquiDistantColorGenerator(numberOfColors)
% [ColorMatrix, angleOnPallet] = EquiDistantColorGenerator(numberOfColors, colorSeed)
% [ColorMatrix, angleOnPallet] = EquiDistantColorGenerator(numberOfColors, colorSeed, outputType)
% [ColorMatrix, angleOnPallet] = EquiDistantColorGenerator(numberOfColors, colorSeed, outputType, plotIt)
%
% DESCRIPTION
% Returns a set of N visually distinct colors sampled (approximately)
% equidistantly from a fixed hue palette. Colors can be returned as RGB
% triples or HEX strings. Optionally supply a seed to reproduce the same
% palette across runs. Optionally display a quick preview plot.
%
% INPUTS
% numberOfColors : (required, positive integer)
% The number of colors N to generate.
%
% colorSeed : (optional, scalar numeric) [default: random seed]
% Seed used to initialize RNG for reproducible color selection. If
% empty or not provided, a random seed is chosen and printed to the
% command window so it can be reused later.
%
% outputType : (optional, char/string) [default: 'rgb']
% Output format for colors:
% 'rgb' : return N×3 double matrix with RGB values in [0,1].
% 'hex' : return N×1 cell array of '#RRGGBB' strings.
%
% plotIt : (optional, logical) [default: false]
% When true (or when no seed is provided), a simple line plot is
% shown to preview the generated colors and their order.
%
% OUTPUTS
% ColorMatrix :
% If outputType = 'rgb' -> N×3 matrix of doubles in [0,1].
% If outputType = 'hex' -> N×1 cell array of '#RRGGBB' strings.
%
% angleOnPallet : N×1 vector of hue “angles” (in degrees) corresponding
% to each returned color’s position on the internal palette.
%
% BEHAVIOR & NOTES
% • Determinism: Using the same (numberOfColors, colorSeed) pair returns
% the same ColorMatrix and angleOnPallet.
% • No seed provided: The function picks a random seed, prints it to the
% command window (e.g., “seed=1234”), and (by default) shows a preview
% plot so you can iterate until you like the palette.
% • Palette: Colors are chosen from a fixed 36-color palette spanning the
% hue circle. Indices are stepped to approximate equal spacing.
% • Legacy special case: For compatibility, if colorSeed == 0.84913 and
% numberOfColors == 4, the first three colors are fixed to a legacy set
% and the 4th is generated from the palette (see code block).
%
% EXAMPLES
% % 1) Random palette, preview shown, seed printed to command window:
% C = EquiDistantColorGenerator(5);
%
% % 2) Reproducible palette (no preview by default):
% C = EquiDistantColorGenerator(5, 897);
%
% % 3) HEX output:
% H = EquiDistantColorGenerator(6, [], 'hex');
%
% % 4) Force preview even with a seed:
% C = EquiDistantColorGenerator(4, 123, 'rgb', true);
%
% SEE ALSO
% colormap, rng, plot, hex2rgb
%
% AUTHOR
% Naveed Reza Aghamohammadi
%
% VERSION
% Initiated: 2022-12-13
% Header updated: 2025-11-13
%
% -------------------------------------------------------------------------

인용 양식

Naveed Reza Aghamohammadi (2025). EquiDistantColorGenerator (https://kr.mathworks.com/matlabcentral/fileexchange/176048-equidistantcolorgenerator), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2022b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
태그 태그 추가
도움

도움 받은 파일: rgb2hex and hex2rgb

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
2.0.0

Better header and new optional output specifying distance among the produced colors

1.0.0