Colormap direction in ribbon plot

3 vues (au cours des 30 derniers jours)
Merijn
Merijn le 8 Déc 2011
Modifié(e) : Voss le 12 Mar 2025
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

Réponses (1)

Naga
Naga le 12 Mar 2025
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

Catégories

En savoir plus sur Blue dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by