Overlaying gradient patches in single plot.
3 次查看(过去 30 天)
显示 更早的评论
I have created two gradient patches: the colormap for one goes from red to white (i.e., [1,0,0] --> [1, 1, 1]) over the range [1000,1600] along the x-axis of a subplot, while the other colormap goes from white to blue (i.e., [1, 1, 1] --> [0, 0, 1]/) over the range [1400, 2000] along the x-axis of a second subplot. xlim for both suplots is [1000, 2000], and I use a for loop with 256 iterations to create the colormaps. Is there any way to superimpose the two patches in one x-y plot (adjusting transparency so that both gradients are visible where the colored portions of the two patches overlap (i.e., x = 1400 --> 1600)? Thanks in advance.
采纳的回答
darova
2021-6-5
编辑:darova
2021-6-5
See this
% x_lo = [1000 ; 1000; 1600; 1600]; % x-limits for RED gradient
% x_hi = [1400 ; 1400; 2000; 2000]; % x-limits for BLUE gradient
% y = [0; 500; 500; 0]; % y-limits for BOTH gradients
num_steps = 10;
x = [linspace(1000,1400,num_steps) linspace(1600,2000,num_steps)]; % x coord
X = [x;x]; % the same top and bottom
Y = [0*x;0*x+500]; % Y coord
c = linspace(0,1,num_steps); % color interpolatioon
red = interp1([0 1],[1 0 0;1 1 1],c); % create red chanel
blu = interp1([0 1],[1 1 1;0 0 1],c); % create blue chanel
C = reshape([red;blu],1,[],3); % 3D matrix of colors
C = [C;C]; % the same top and bottom
surf(X,Y,X*0,C)
view(0,90)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!