Multi line color in graph
显示 更早的评论
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
采纳的回答
Try this:
cmap = colormap(gray(10));
figure
hp = plot(1:10, rand(10));
set(gca,'ColorOrder',cmap)
Experiment to get dufferent results.
12 个评论
Sorry, it didn't work. I still see multiple colors
It works correctly for me in R2019b:

It plots only gray lines.
Deepa Maheshvare
2019-11-6
编辑:Deepa Maheshvare
2019-11-6
Thank you. I am using R2019a. I will upgrade the MATLAB version.
My pleasure.
My code should work in R2019a.
Unfortunately, I could only obtain this in 2019a

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.
@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.
Deepa, do you happen to be using MacOS Catalina ?
Walter, I am uisng Windows OS. I upgraded from 2019a to 2019b. The solution that was posted earlier works fine now. Thank you
@Deepa Maheshvare — Thank you for following up. I am happy that it worked for you.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Color and Styling 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
