Colormap direction in ribbon plot

조회 수: 3 (최근 30일)
Merijn
Merijn 2011년 12월 8일
편집: Voss 2025년 3월 12일
I'm trying to make a ribbon plot with a scaled CDatamapping colormap. How can I change the axis of the colormap? For example:
[x,y] = meshgrid(-3:.5:3,-3:.1:3);
z = peaks(x,y);
ribbon(y,z)
xlabel('X')
ylabel('Y')
zlabel('Z')
colormap jet
creates a ribbon plot with colormapping in the x-direction. I would like to have the colormapping in the z-direction. Any ideas how to do this? Thank you

답변 (1개)

Naga
Naga 2025년 3월 12일
To change the colormapping of a ribbon plot to be based on the z-direction instead of the x-direction, you can manipulate the 'CData' property of the surface objects created by the ribbon. By default, the ribbon plot uses x-values to determine the color mapping. By setting 'h(i).CData = z(:, i);', you use the z-values to determine the color of each ribbon. Ensure the 'CDataMapping' property is set to 'scaled' so that the colormap is scaled according to the range of z-values.
Here’s how you can achieve this:
[x, y] = meshgrid(-3:0.5:3, -3:0.1:3);
z = peaks(x, y);
h = ribbon(y, z);
% Set the colormap
colormap jet
% Adjust the CData property to use z-values for coloring
for i = 1:length(h)
h(i).CData = z(:, i);
end
set(h, 'CDataMapping', 'scaled');
xlabel('X')
ylabel('Y')
zlabel('Z')
% Add colorbar for reference
colorbar

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by