Use of 2D colormaps possible in Matlab?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Dave B
le 22 Nov 2021
Modifié(e) : Dave B
le 22 Nov 2021
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Orange dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!