Creating rgb vector based on Z data for standard colorbar
14 次查看(过去 30 天)
显示 更早的评论
I have Z data for my x, and y data for which I would like to plot in a standard plot using the z data as a colorbar. I know that using the handle 'color' you can specify a nx3 vector for the n points of x and y data you have. If I use the standard 'colorbar' option, how can I create these color vectors based on the values of z of my data?
For example:
x=linspace(0,10)
y=linspace(0,10)
z=rand(1,100)
% now I want to plot z and convert the values in their respective colors
% where the highest color will be yellow and lowest color blue
0 个评论
采纳的回答
DGM
2021-6-4
编辑:DGM
2021-6-4
This is an old method. I kind of wonder if there's anything newer that makes this simple...
% make a custom colormap
n = 256; % how many levels do you want?
cvu = linspace(0,1,n).';
cvd = flipud(cvu);
cmap = [cvu cvu cvd];
N = 100; % how many points to plot?
x=linspace(0,10,N);
y=linspace(0,10,N);
z = sin(linspace(-pi/2,pi/2,N)); % i picked something else
% instead of using plot(), use surf()
% because it can do color interpolation
h = surf([x(:) x(:)],[y(:) y(:)],[z(:) z(:)]);
set(h,'facecolor','none','edgecolor','interp');
set(h,'linewidth',3); % make it fat so it's easier to demonstrate
view(2); % only show 2-D view
colormap(cmap);
colorbar
To see what the 'interp' option does, set N = 10 and then run it. The plot will still be a uniform gradient. Set 'edgecolor' to 'flat' and run again. The line color will be 10 discrete steps.
Afaik, plot doesn't really have any way to utilize a colormap, interpolated or flat/faceted. Something like scatter() can do color interpolation, but afaik, you can't connect the markers.
0 个评论
更多回答(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!