Use of 2D colormaps possible in Matlab?
4 次查看(过去 30 天)
显示 更早的评论
Is there a way to use colormaps in Matlab which change in two dimensions?
If yes, how? And how do you create them?
One example could be to have magitude and orientation of a 2D vector field in one plot.
I have found some examples on other platforms:
Or this discussion here about circular 2D colormaps:
Best regards
0 个评论
采纳的回答
Dave B
2021-11-22
编辑:Dave B
2021-11-22
There's nothing (that I know of) that provides this as a built-in utility in MATLAB, but it's pretty easy to do this kind of thing by interpolating indices into a colormap. For example, to recreate the scatter at the top of the link:
%% Load a colormap and store in a matrix of RGB values
im = imread('https://dominikjaeckle.com/projects/color2d/data/bremm.png');
rgb = double(reshape(im, [], 3))./255;
%% Example mapping
x=rand(100,1);
y=rand(100,1);
% interpolate to find a color for each x and y, mapping the range of the
% colormap onto [0 1]
c_column=round(interp1(linspace(0,1,size(im,2)), 1:size(im,2), x));
c_row=round(interp1(linspace(0,1,size(im,1)), 1:size(im,1), y));
rgb_row=sub2ind(size(im),c_row,c_column,ones(size(c_row))); % this is the same as the index into im of red values
c=rgb(rgb_row,:);
%% Make some plots
t=tiledlayout(1,3);
nexttile;image(im)
nexttile;scatter(x,y,'filled')
nexttile;scatter(x,y,[],c,'filled')
set(t.Children,'XTick',[],'YTick',[],'box','on','DataAspectRatio',[1 1 1],'YDir','reverse')
4 个评论
更多回答(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!