File Exchange

image thumbnail


version (1.83 KB) by Daniel Helmick
Provides maximum color variation for lines on plots.


Updated 13 Aug 2008

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

I was unhappy with the current implementation of the color schemes. This provides a way for a program to dynamicly scale the number of different colors on plots, and it ensures there won't be any color overlap.

Cite As

Daniel Helmick (2021). varycolor (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (32)


Lately it gives the warning:
Warning: NARGCHK will be removed in a future release. Use NARGINCHK or NARGOUTCHK instead.
> In varycolor (line 26)


which version of matlab can i use the function?
because i use 2018b but it dosen't work, even i just copy code.

Bahareh Kiani

Shanning Bao

Very useful! many colors you can choose

noga larry

Ohad Zivan

Jeremy Maurer

Very helpful plotting function!

Yuan Gao

Sam Horne

Hannes Mogensen

I have used this function A LOT! Very useful.


Goncalo, I am not sure if I fully understand what you are trying to do. This might be what you want.

dot_array = rand(10,44);
ColorSet = varycolor(10);
% each row gets its own color

for i = 1:10
x = 1:44; % need x values for plot
y = dot_array(i,:); %nab the ith row
h = plot(x,y);
hold all;
legend show Location NorthEastOutside

Gonçalo Figueira

does this applies to dot plots instead of lines?


dot_array = rand(10,44);
ColorSet = varycolor(44);

for i = 1:10

legend show Location NorthEastOutside
set(gca, 'ColorOrder', ColorSet);
hold all;

for ii = 1:44
plot(i,dot_array(i,ii); hold on

It's not working... Can anyone help me with this?


It served my purpose completely. There is now a more sophisticated function inspired by this file, "Generate maximally perceptually-distinct colors".

Felipe G. Nievinski

I found "Generate maximally perceptually-distinct colors" to be better in the case of a few lines.

jeong woo


Subhashree Mishra


Very useful! Thanks a lot!

Benjamin I



Very helpful!


Nick Sinclair

Fabio Caponetti

Good and functional. Should be shipped as default configuration in the Matlab package.

Kamil Wojcicki


Daniel Helmick

Ryan, it sounds like you are going to be disappointed in this 'maximum' color separation too.

Open the file up, and you will see that this one is not 'maximum' for small numbers of line colors. Depending on how you quantify color separation, even large numbers of line colors could be argued to be non-maximum in some metrics.

I suspect CMAPLINE provides results more in line with your desires.

Ryan Ollos

Your function is nice. I have been trying to do something similar, in order to create a maximum number of distinct line colors to use as the axes ColorOrder. I haven't been able to figure out an algorithm which produces maximum color variation, and at the same time convince myself that the algorithm really gives the 'maximum' color variation.

So, my question is, how did you come up with the RGB curves, and if/how do you know that it is really optimal in terms of maximizing color variation?

Nikola Toljic


Daniel Helmick

Yes, thank you. I saw those and wasn't happy. The pick of the week description does an excellent job of pointing out some of the utility with this file.

Matt S

Carlos Adrian Vargas Aguilera

Daniel, have you seen MATLAB's COLORMAP, JET, GRAY, LINES, etc?, or the functions at the FEx that lets you create a different colormap like USERCOLORMAP?

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!