File Exchange

image thumbnail

Custom Colors for Plots

version 1.0.0.0 (1.88 KB) by Andres
This function provides a selection of colors easy to differentiate for plotting graphics.

0 Downloads

Updated 03 May 2012

View License

In plot graphs, often it's needed to use a several colors that can be easily differentiated on a first look on the graphic. With this function you can call easily (by name or by code) a selection of 15 colors.
It's very simple and there are more elegant ways to do it, but I think it's a very functional solution.

Examples:
for ccc=1:15
plot(ccc*ones(1,10),'Linewidth',4,'Color', CustomColors(ccc))
end

plot(ones(1,10),'Linewidth',4,'Color', CustomColors('Coral'))
plot(ones(1,10),'Linewidth',4,'Color', CustomColors('DeepSkyBlue4'))

Comments and Ratings (3)

Jessica77

Julian

Sweet! thanks

Jan

I cannot really distinguish the colors magenta4 and darkorchid on my screen.
The "for ct2" loop to find a matching name is inefficient. Better: "ct2 = find(strcmpi(NColors, ct1));"
fprintf() is more efficient than disp(sprintf()) as recommended by MLINT.
There is no need to enclose vectors in double square brackets.

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags
Acknowledgements

Inspired: Maximally Distinct Color Generator

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor