Specific color corresponding to specific data using contourf colormap
Show older comments
Hello,
I would like to know if we can give a specific color to a specific data and plot them on Matlab ?
For example, I have a 3000x3000 matrix with x and y axis, I need to plot a range of data in a specific color.
I've already generated the map with, but the colors are random
this is my code :
A= data;
figure;
[v,x] = meshgrid(v,x);
contourf(v,x,A)
figure;
%colourRGB = hsv(jet);
c=colormap(jet); %jet
L=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
[cdd hc]=contourf(v,x,A,[-0.01 L]);
Recolor_contourf(hc,c,L,'vert');
I want for example if A(x,y)==0.07 the colormap will be green ...
I can give more details.
Kind regards,
S.C
6 Comments
DGM
on 12 May 2021
I don't have an answer, but as far as I know, Recolor_contourf() has been broken since about R2014b or so.
S Ch
on 13 May 2021
DGM
on 13 May 2021
I don't really have an alternative for it. I'm not really familiar with it, and since I can't run it, I'd pretty much have to reverse-engineer it in order to know for sure how to replace the functionality.
But regarding the rest of the question, is this something that can be done by customizing the colormap (colormapeditor())?
J. Alex Lee
on 13 May 2021
If your mapping between value and color is linear, it should be a matter of matching up the axes CLim property with the limits of your data. If your mapping is nonlinear i think you just need to code in the mapping as an intermediary between your actual data and the "data" that you ultimately construct your contour plot from.
want to post your data? and ideally a sketch of what you want ultimately?
DGM
on 13 May 2021
I'm still not really sure what you're aiming for, but consider:
% make some simple test data
x = linspace(0,1,100);
y = x.';
z = (x+y)/2;
% this is a simple colormap with 10 colors
% it looks pretty terrible, but they're distinct
% and recognizable
cm = [1 0 0;
1 1 0;
0 1 0;
0 1 1;
0 0 1;
1 0 1;
0.8 0 0;
0.8 0.8 0;
0 0.8 0;
0 0.8 0.8];
c=colormap(cm);
% the levels vector also has 10 levels
L=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
[cdd hc]=contourf(x,y,z,[-0.01 L]);

Now each band on the contour plot has a distinct color directly represented by the colormap. You could build whatever colormap you want to assign to each level. If you want to use jet or another built-in colormap the same way, specify the number of levels so that it lines up with your levels vector:
c=colormap(jet(10)); % or however many levels you have

Or you could modify a built-in map if you want to highlight certain things:
cm = jet(10); % use jet
cm(7,:) = [1.0000 0.2726 0.6517]; % but make one band pink
c=colormap(cm);

Is this even getting close to what you need?
S Ch
on 17 May 2021
Answers (2)
Chad Greene
on 13 May 2021
0 votes
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!