Colormap direction in ribbon plot
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Blue에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

