Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Coloring each line in a stairs graph with a different color

Asked by Cecile on 16 Jul 2013

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 Comments

Cecile

Tags

Products

No products are associated with this question.

1 Answer

Answer by kjetil87 on 19 Jul 2013

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 :)

1 Comment

Cecile on 13 Sep 2013

Thank you very much, it worked using hold on.

kjetil87

Contact us