Hi,
While trying to plot a graph
plot(1:10, rand(10,10))
Each line has a different color.
Is it possible to vary the color scale from a darker shade to lighter shade? For instance, from black to grey

 채택된 답변

Star Strider
Star Strider 2019년 11월 5일

1 개 추천

Try this:
cmap = colormap(gray(10));
figure
hp = plot(1:10, rand(10));
set(gca,'ColorOrder',cmap)
Experiment to get dufferent results.

댓글 수: 12

Deepa Maheshvare
Deepa Maheshvare 2019년 11월 5일
Sorry, it didn't work. I still see multiple colors
Star Strider
Star Strider 2019년 11월 5일
It works correctly for me in R2019b:
Multi line color in graph - 2019 11 05.png
It plots only gray lines.
Deepa Maheshvare
Deepa Maheshvare 2019년 11월 6일
편집: Deepa Maheshvare 2019년 11월 6일
Thank you. I am using R2019a. I will upgrade the MATLAB version.
Star Strider
Star Strider 2019년 11월 6일
My pleasure.
My code should work in R2019a.
Deepa Maheshvare
Deepa Maheshvare 2019년 11월 6일
Unfortunately, I could only obtain this in 2019a
Untitled.png
Walter Roberson
Walter Roberson 2019년 11월 6일
There was a change in r2019b about color order, such that it now affects lines already drawn. In previous versions you need to set the color order before you draw the lines.
Star Strider
Star Strider 2019년 11월 6일
@Walter — I didn’t realise that. Thank you!
cmap = colormap(gray(10));
figure
set(gca,'ColorOrder',cmap)
hp = plot(1:10, rand(10));
I tried the above. It didn't work either.
Could you please suggest what's going wrong?
I wish I could, since the code I posted works for me. The code appears to be correct, according to the ColorOrder property documentation. (The colororder function is new in R2019b.)
The set call should not be a problem, however the only thing I can think of at this point is to use a slightly different calling syntax:
cmap = colormap(gray(10));
figure
hp = plot(1:10, rand(10));
Ax = gca;
Ax.ColorOrder = cmap;
This also worked when I tried it.
Walter Roberson
Walter Roberson 2019년 11월 6일
Deepa, do you happen to be using MacOS Catalina ?
Deepa Maheshvare
Deepa Maheshvare 2019년 11월 7일
Walter, I am uisng Windows OS. I upgraded from 2019a to 2019b. The solution that was posted earlier works fine now. Thank you
Star Strider
Star Strider 2019년 11월 7일
@Deepa Maheshvare — Thank you for following up. I am happy that it worked for you.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 11월 5일

댓글:

2019년 11월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by