How can I add color to predefined?

4 views (last 30 days)
Patrik Ek
Patrik Ek on 13 Mar 2014
Edited: Patrik Ek on 14 Mar 2014
Hi,
The plot function have a set of 7 colors that are predefined and can be added as
plot(any_x,any_y,'r');
There are seven colors, where 5 of them are suitable for plotting (white and yellow is hard to see). I like to work with different colors, because this makes it much easier to distiguish differences in plots and to keep an eye of which plot is which.
However, the problem is that sometimes I need more colors than 5. I know that it is possible to use subplots, linestyle, ... to improve this, lets say that you want to plot I different quantity as
plot(any_x,any_y,'r.');
for different data in separate plots and want to be able to enlarge the plot if necessary (which is impossible with subplot). You may also want to plot 10 polygons in the same plot and then is may be annoying to have to make a double loop and so to change linestyle.
The above is a motivation to where it may be necessary to have more colors and since the keyword is simplicity here. The simplest solution is then clearly,
colorloop = 'bgrkm';
for datai = 1:min(size(datax))
plot(datax(datai,:),data(datay,:),color,colorloop(mod(datai-1,5)+1)),'linestyle','.');
end
or similar. This is why I wonder, are there ways to add a color to the predefined, that would simplify everything a lot.
  1 Comment
Patrik Ek
Patrik Ek on 13 Mar 2014
It is possible that you cannot do this, but if anyone knows I would be delighted.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Mar 2014
You cannot add new color names to the list of predefined color names, sorry.
You can work with the axes color order parameters and "hold all" to set RGB colors in sequence for your various plots.
  1 Comment
Patrik Ek
Patrik Ek on 14 Mar 2014
Edited: Patrik Ek on 14 Mar 2014
Thanks for the answer, I guess it makes sense since the functions are probably built in, But there are no functionality that can do something like
Template<char c>
function plot(plotdata,c)
if strcmpi(c,'i') || strcmpi(c,'ice')
c = [0.6 1 1];
end
plot(plotdata,'color',c);
end
so that you can create a "plot template like" thing, without overloading the plot function? I guess that I could create an ordinary matlab function for this, but it would be a shame to replace the plot function with a custom one calling the plot function. However, this could be the best option if nothing else work, I could then include it in some separate folder that is not include in the path by default.

Sign in to comment.

More Answers (1)

nl2605
nl2605 on 13 Mar 2014
Probably this might help you. It helped me.
  3 Comments
nl2605
nl2605 on 13 Mar 2014
Got it. Will be careful next time.
Patrik Ek
Patrik Ek on 13 Mar 2014
Thanks for answering me, but the question is a bit mor complex than that. I want (if possible) to add a color to the predefined colors, so that I can type from a completely clean workspace something like,
x = 0:0.1:10;
y = sin(x);
plot(x,y,'i');
and then get the color ice, which is not a standard matlab color. I am completely aware of that I first must make sure that the whatever operator I select is free to make sure there are no operator overloading. The use of i is only an example. The question is more like " are there anything similar to the c++ templates that can be used to add colors to predefined?"
Frankly I doubt it is even possible, but I posted a question to see if anyone have some done something that, may work in a similar way at least. The task of first selecting good colors and then use it is a pain to go through every time. When I comment this I will also make sure to point out that I also would like to know if I can revert it afterwards. or if it is built into matlab forever if this is done.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!