How to specify the color of each face independently? Either using plot3 or waterfall plot

조회 수: 7 (최근 30일)
I want to be able to change the color of each face to be different. Is there a way to do that? Either waterfall or plot3, but open to other options as well.
%Data
x = [3 4 5 6 7 8];
y = 1:10;
z = [0.557668282000000 0.338441078000000 0.234647830000000 0.171571534000000 0.145776360000000 0.145776360000000;
0.518295499000000 0.405863916000000 0.400123394000000 0.306492064000000 0.264851392000000 0.220965997000000;
0.546313444000000 0.328483225000000 0.226840432000000 0.161622549000000 0.137061307000000 0.103935323000000;
0.508053348000000 0.390929752000000 0.377395056000000 0.291840789000000 0.251892663000000 0.211123492000000;
0.528207477000000 0.314119939000000 0.215415213000000 0.149739334000000 0.124970443000000 0.092681414000000;
0.492618639000000 0.367508278000000 0.341235709000000 0.270810866000000 0.232835907000000 0.192588062000000;
0.496943074000000 0.291760348000000 0.197562551000000 0.135737349000000 0.107583568000000 0.079613728000000;
0.468728144000000 0.317795980000000 0.279181733000000 0.216618451000000 0.183463664000000 0.149361397000000;
0.423083710000000 0.245707347000000 0.158596551000000 0.113084732000000 0.082281339000000 0.061452252000000;
0.416533294000000 0.250013365000000 0.165840410000000 0.125008755000000 0.120307120000000 0.089384088000000];
%Plot
j = waterfall(x,y,z);
j.FaceColor = [1 0 0]; %change color of all faces to red, trying to do each face a different color.

채택된 답변

Mathieu NOE
Mathieu NOE 2025년 4월 14일
let's try something
%Data
x = [3 4 5 6 7 8];
y = 1:10;
z = [0.557668282000000 0.338441078000000 0.234647830000000 0.171571534000000 0.145776360000000 0.145776360000000;
0.518295499000000 0.405863916000000 0.400123394000000 0.306492064000000 0.264851392000000 0.220965997000000;
0.546313444000000 0.328483225000000 0.226840432000000 0.161622549000000 0.137061307000000 0.103935323000000;
0.508053348000000 0.390929752000000 0.377395056000000 0.291840789000000 0.251892663000000 0.211123492000000;
0.528207477000000 0.314119939000000 0.215415213000000 0.149739334000000 0.124970443000000 0.092681414000000;
0.492618639000000 0.367508278000000 0.341235709000000 0.270810866000000 0.232835907000000 0.192588062000000;
0.496943074000000 0.291760348000000 0.197562551000000 0.135737349000000 0.107583568000000 0.079613728000000;
0.468728144000000 0.317795980000000 0.279181733000000 0.216618451000000 0.183463664000000 0.149361397000000;
0.423083710000000 0.245707347000000 0.158596551000000 0.113084732000000 0.082281339000000 0.061452252000000;
0.416533294000000 0.250013365000000 0.165840410000000 0.125008755000000 0.120307120000000 0.089384088000000];
%Plot
j = waterfall(x,y,z,zeros(size(z)));
set(j, 'FaceColor', 'flat');
set(j, 'EdgeColor', 'k');
set(j, 'FaceVertexCData', rand(size(z,1),3)) % random colors
  댓글 수: 3
Keyur Savla
Keyur Savla 2025년 4월 14일
편집: Keyur Savla 2025년 4월 14일
Thank you that solved the main query, how do I match the edgecolor to that of the face color?
I tried changing the edgecolor value to 'flat' but that creates an error, am I missing anything?
I do not want the edgecolor to be none, I want the edge to be visible.
Mathieu NOE
Mathieu NOE 2025년 4월 14일
well , between no edges and edges of same color as the face, I don't see a big difference in how the result will look like
and "no edges" seems to be here the only option that works or maybe there's a trick I am currently unaware of (?)
or you have to build your own version of waterfall (I don't have the time...)
%Data
x = [3 4 5 6 7 8];
y = 1:10;
z = [0.557668282000000 0.338441078000000 0.234647830000000 0.171571534000000 0.145776360000000 0.145776360000000;
0.518295499000000 0.405863916000000 0.400123394000000 0.306492064000000 0.264851392000000 0.220965997000000;
0.546313444000000 0.328483225000000 0.226840432000000 0.161622549000000 0.137061307000000 0.103935323000000;
0.508053348000000 0.390929752000000 0.377395056000000 0.291840789000000 0.251892663000000 0.211123492000000;
0.528207477000000 0.314119939000000 0.215415213000000 0.149739334000000 0.124970443000000 0.092681414000000;
0.492618639000000 0.367508278000000 0.341235709000000 0.270810866000000 0.232835907000000 0.192588062000000;
0.496943074000000 0.291760348000000 0.197562551000000 0.135737349000000 0.107583568000000 0.079613728000000;
0.468728144000000 0.317795980000000 0.279181733000000 0.216618451000000 0.183463664000000 0.149361397000000;
0.423083710000000 0.245707347000000 0.158596551000000 0.113084732000000 0.082281339000000 0.061452252000000;
0.416533294000000 0.250013365000000 0.165840410000000 0.125008755000000 0.120307120000000 0.089384088000000];
%Plot
mycolors = rand(size(z,1),3);
j = waterfall(x,y,z,zeros(size(z)));
set(j, 'FaceColor', 'flat');
set(j, 'FaceAlpha', 0.5);
set(j, 'EdgeColor', 'none');
set(j, 'FaceVertexCData', mycolors) % random colors

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by