フィルターのクリア

Use of 2D colormaps possible in Matlab?

5 ビュー (過去 30 日間)
Marcus Becker
Marcus Becker 2021 年 11 月 22 日
コメント済み: Marcus Becker 2021 年 11 月 23 日
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

採用された回答

Dave B
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 件のコメント
Marcus Becker
Marcus Becker 2021 年 11 月 22 日
For me, ideally there would be function calls like
mesh4d(x,y,u,v,ulabel,vlabel,'Cmap2d','bremm')
or
scatter4d(x,y,u,v,'Cmap2d','bremm')
which provide a selection of useful colormaps and maybe even an interface for custom ones.
Issue might be that the colorbar becomes a colorplane and needs x and y labels.
But I do think that it would be helpful to put it on file exchange!
Marcus Becker
Marcus Becker 2021 年 11 月 23 日
I have created a Git with a working version of the function. It's not amazing code but it works for my needs:
Feel free to use, share, adapt.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by