Surf color based off of greater than or less than a number
조회 수: 8 (최근 30일)
이전 댓글 표시
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
채택된 답변
DGM
2025년 3월 14일
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
DGM
2025년 3월 17일
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];
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!