Surf color based off of greater than or less than a number
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I was able to create a surf plot where values greater than 1000 are red and less than 1000 are blue. Is there a way that I could use different shades of red and blue depending how far away from 1000 it is, darker the farther. And how can I make a range of values for the greenchannel? Also is there a better way to do this as 1 side of the plot is black.
z = U_ku;
redChannel = z > 1000;
greenChannel = 0*z;
blueChannel = z < 1000;
% Make the RGB image.
colors = double(cat(3, redChannel, greenChannel, blueChannel));
% Plot the surface with those colors.
surf(z, colors);
0 commentaires
Réponse acceptée
DGM
le 14 Mar 2025
There are a bunch of blue-red colormap generators out there, or you could create your own. Either way, this is one way to apply it. Instead of trying to directly color the surface, use the scaled colormapping functionality of the graphics system.
% some fake data
x = 0:50;
y = x.';
z = x.*y;
% plot it
hs = surf(x,y,z);
hs.EdgeColor = 'none';
% create a symmetric colormap
ncolors = 256;
CT = bluewhitered1(ncolors);
% set the colormap
colormap(CT)
% set the climits to be symmetric about the center threshold
thresh = 1000;
halfwidth = max(abs(zlim() - thresh));
clim(thresh + [-1 1]*halfwidth)
I attached a handful of similar simple map generators. There are others on the File Exchange. Otherwise, you can open up any of the attached files and edit the breakpoint locations or colors to make your own.
6 commentaires
DGM
le 17 Mar 2025
Sorry about being late. My garbage computer is in its death throes.
If you want to adjust the colors a bit easier, you could do something like this.
% you can define these as input arguments to your function if you want
basecolors = [0 0 1; 0 0.8 0; 1 0 0]; % the colors near the center band
darkenamt = 0.7; % the amount by which the top and bottom colors get darkened
% then make the color table segments based on those parameters
CT1 = makectf(max(basecolors(1,:)-darkenamt,0),basecolors(1,:),bw(1),'srgb');
CT2 = repmat(basecolors(2,:),[bw(2) 1]); % all green
CT3 = makectf(basecolors(3,:),max(basecolors(2,:)-darkenamt,0),bw(3),'srgb');
CT = [CT1; CT2; CT3];
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Scatter Plots 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!




