How to specify the RGB color of each line in a waterfall plot?

10 views (last 30 days)
Is there a way to specify the RGB color of each line in a waterfall plot? It seems like I can't set the 15 individual lines' edge color to the corresponding rgbDesired values in the w1 patch example below. I could plot each 'line' as a separate vertical patch and set its edge color individually, but is there a better way?
figure;
[X,Y,Z] = peaks(50);
% Make different x,y dimensions to make it easier to understand
ix = 1:15; % Will produce 15 lines
iy = 1:20;
X = X(ix, iy); Y = Y(ix, iy); Z = Z(ix, iy);
w1 = waterfall(X,Y,Z); % Waterfall with color set by peak height
% Alternative RGB values we seek to use for each line
rgbDesired = rand(length(ix), 3);
w1 =
Patch with properties:
FaceColor: [1 1 1]
FaceAlpha: 1
EdgeColor: 'flat'
LineStyle: '-'
Faces: [15×25 double]
Vertices: [375×3 double]

Accepted Answer

Adam
Adam on 21 Feb 2017
I'm not really familiar with waterfall plots, but when I run your code there are 15 lines and the CData is also 15x25 so I'm not sure where 20 colours would fit exactly.
You can edit the whole CData at once, e.g.
w1.CData = rand( 25, 15, 3 );
but it has to be the expected size.
  1 Comment
KAE
KAE on 21 Feb 2017
Edited: KAE on 9 Oct 2018
What I am trying to do is to make each of the 15 lines have a solid color that I specify. So I altered your answer code as follows, and it works great,
% Expand desired RGB line colors from dimensions 15x3 to 25x15x3
rgbDesiredBigger = repmat(reshape(rgbDesired, [1 15 3]), [25 1 1]);
w1.CData = rgbDesiredBigger;

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!