Coloring each line in a stairs graph with a different color
5 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to color each horizontal line of the stairs I am creating in a different color.
demand = [0, 117, 38, 35, 160];
prices = [-1, 0, 0.62, 9.6, 8.9];
[~, idx] = sort(prices);
cumVolume = cumsum(demand(idx));
stairs(cumVolume, prices(idx));
In above example, I have 4 horizontal lines in my stairs and I would like each of them to be displayed in a different color.
Could you please help me with that ?
Thank you very much.
Cecile
0 个评论
回答(1 个)
kjetil87
2013-7-19
if instead return the plot values:
[xx,yy]=stairs(cumVolume, prices(idx))
you can plot it multiple times using the
hold on
command.
e.g:
plot(xx,yy,'b');
hold on;
plot(xx(1:end-3),yy(1:end-3),'c')
plot(xx(1:end-5),yy(1:end-5),'r')
plot(xx(1:end-7),yy(1:end-7),'g')
for a bigger plot you need to make a loop or something, and use a color index array or something like that. Not the best code but it will do the trick :)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!