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!

