How do I plot a third variable as line color???

32 Ansichten (letzte 30 Tage)
Jason Manley
Jason Manley am 17 Jun. 2015
Kommentiert: Eko am 30 Jan. 2024
Hello all--
I'm looking to plot many curves (given by cells X and Y), and I'd like to specify the color of each curve by a third variable (array Z) and display a colorbar for Z.
Currently this is my code:
for i=1:length(X)
plot(X{i}, Y{i}, 'color', [1 0 Z(i)/max(Z)])
end
This allows me to plot each line as varying shades based on Z, but I have no clue how to make a colorbar.
Any help would be much appreciated!
Thanks, Jason

Akzeptierte Antwort

Tim
Tim am 17 Jun. 2015
I think this should work for you:
Z=1:1:100;
%Colormap is defined as a 3 column matrix, each row being an RGB triplet
map = zeros(numel(Z),3);
map(:,1)=1;
map(:,2)=0;
map(:,3)=Z./max(Z);
%Set the current Colormap
colormap(map);
%Display Colorbar
colorbar
  2 Kommentare
Jason Manley
Jason Manley am 18 Jun. 2015
That's perfect! Thank you!
Eko
Eko am 30 Jan. 2024
Would you please share the final script?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Colormaps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by