필터 지우기
필터 지우기

Can I specify the color of a graphics object by its index in the ColorOrder?

조회 수: 4 (최근 30일)
Ulrich Reif
Ulrich Reif 2021년 8월 16일
댓글: Stephen23 2021년 8월 17일
Specifying colors of graphics objects by characters is most convenient, like in
plot([1 2],'r--')
Is there a similar way to select colors by their index in the ColorOrder? That is, I am looking for something like
plot([1 2],'2--')
as an abbreviation for
c = get(gca,'ColorOrder');
plot([1 2],'--','Color',c(2,:))
If not (as I assume) it would be really great to have that in a future release.
  댓글 수: 8
DGM
DGM 2021년 8월 17일
편집: DGM 2021년 8월 17일
Then let me ask your opinion on what might be an alternative. Given that the flexibility of the simplified syntax for plot() would lead to ambiguities if trying to basically cram another parameter into the string, what about using the new colororder() function? Would it be possible/practical/more elegant to provide an unambiguous means of directly addressing in a call to colororder()?
Something like
secondtuple = colororder(axishandle,2);
or something similar that would allow colororder() to be used inline?
plot(mydata,'--','Color',colororder(gca,2))
Or would there be a better way other than just pulling the color table in a separate line?
Stephen23
Stephen23 2021년 8월 17일
I second this proposed syntax:
plot(..,'Color',index)

댓글을 달려면 로그인하십시오.

답변 (2개)

Wan Ji
Wan Ji 2021년 8월 16일
If you want different colors, you can use matlab build-in color series like jet, hsv, bone, copper. Eaxmples are
n = 1:6;
color = jet(length(n));
x = 0:0.1:7;
hold on
a = arrayfun(@(i)plot(x,gampdf(x,n(i)),'color',color(i,:)), 1:length(n));
legend(arrayfun(@(i)['\Gamma(',num2str(n(i)),',1)'],1:1:length(n),'uniform',false))
You can also use random colors
n = 1:6;
color = rand(length(n),3);
x = 0:0.1:7;
hold on
a = arrayfun(@(i)plot(x,gampdf(x,n(i)),'color',color(i,:)), 1:length(n));
legend(arrayfun(@(i)['\Gamma(',num2str(n(i)),',1)'],1:1:length(n),'uniform',false))
Actually, color in matlab is a 1x3 array with interval [0,1]
  댓글 수: 4
Wan Ji
Wan Ji 2021년 8월 17일
편집: Wan Ji 2021년 8월 17일
how many colors there are! I dont think this idea is brilliant. Just use the existing colors or color tables are enough to tell people the differences of all the curves.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2021년 8월 16일
See my attached demo that shows you how to change the default color order:
The demo allows you to pick from the set of 20 or so built-in colormaps (I used jet in the demo above), though you could of course define your own custom colors. Adapt as needed.
  댓글 수: 1
DGM
DGM 2021년 8월 16일
OP wasn't asking how to assign a new color table to the 'colororder' property, but rather if there were a more convenient method to specify a color by its index within the existing colortable set in 'colororder' -- whatever colortable that might be at the time.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by