How can I add color to predefined?

2 次查看(过去 30 天)
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 个评论
Patrik Ek
Patrik Ek 2014-3-13
It is possible that you cannot do this, but if anyone knows I would be delighted.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2014-3-13
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 个评论
Patrik Ek
Patrik Ek 2014-3-14
编辑:Patrik Ek 2014-3-14
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.

请先登录,再进行评论。

更多回答(1 个)

nl2605
nl2605 2014-3-13
Probably this might help you. It helped me.
  3 个评论
nl2605
nl2605 2014-3-13
Got it. Will be careful next time.
Patrik Ek
Patrik Ek 2014-3-13
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by