Plotting multiple lines with difference specific colours via plot function

3 Ansichten (letzte 30 Tage)
Is there any way to use the plot function to plot multiple lines, each having a specific colour?
e.g plot(x1,y1,'-','color',[0 0 1],x2,y2, '-', 'color',[1 0.4 0.6])
This doesn't work, but is there any way of properly doing this?

Antworten (2)

Kaelan Wade
Kaelan Wade am 1 Mai 2017
You can't combine everything into one single plot function.
What you can do is combine different plots via using hold on/off
E.g plot(x1,y1,'-','color',[0 0 1]) hold on plot(x2,y2, '-', 'color', [1 0.4 0.6]) hold off
  1 Kommentar
Stephen23
Stephen23 am 1 Mai 2017
Bearbeitet: Stephen23 am 1 Mai 2017
"You can't combine everything into one single plot function." Really?
See my answer for the correct way of doing this without requiring multiple plot calls.

Melden Sie sich an, um zu kommentieren.


Stephen23
Stephen23 am 1 Mai 2017
Bearbeitet: Stephen23 am 1 Mai 2017
You just need to set the line ColorOrder property of the axes, then you just need one plot call:
>> map = [0,0,1;1,0.4,0.6];
>> axes('ColorOrder',map,'NextPlot','replacechildren')
>> plot([0,1],[1,2],'-',[0,1],[2,1],'*-')

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by