How can I add color to predefined?

조회 수: 2 (최근 30일)
Patrik Ek
Patrik Ek 2014년 3월 13일
편집: Patrik Ek 2014년 3월 14일
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