Can I set explicit plot colors for specific values or value ranges

16 Ansichten (letzte 30 Tage)
I am creating a sinlge figure output containing multiple plot elements:
surface
contour3
scatter
For the surface plot, if the value is < 1, I want it to plot in green, if the value is >= 1 I want it to plot in blue.
For the contour3 plot, if the value is >= 25, I want it to plot in red
For the scatter plot, I want the default color of blue for the circles.
Is this possible?

Akzeptierte Antwort

ChristianW
ChristianW am 11 Feb. 2013
Yes its possible, only for contour3 its a bit fumbling.
Surface function has an input for the colormatrix C. C is referring to the colormap. Example:
P = peaks;
C(P<1) = 1; % 1 means first color in colormap
C(P>=1) = 2;
C = reshape(C,size(P));
cmap = [0 1 0; 0 0 1]; % check colormap: colormap(cmap); pcolor(cmap)
figure; surface(peaks,C); view(-35,45)
colormap(cmap)
This contour example checks where the limit value is located in the colormap. Then defining all colors from that location to the end as RED.
figure; contour3(P,40); grid off; view(-25,35)
red_limit = 2;
cmap_contour = jet;
cl = caxis;
I_red = ceil((red_limit-cl(1))/range(cl)*size(cmap_contour,1));
% make colormap from I_red_limit to end all RED
cmap_contour(I_red:end,:) = repmat([1 0 0],size(cmap_contour,1)-I_red+1,1);
colormap(gca,cmap_contour)
In scatter you can define it directly with the markertype input:
scatter(rand(200,1),rand(200,1),'ob') % 'ob' = circle blue
Alternatively you can search the whole figure for circle marker and than make them blue:
figure; hold on; box on
scatter(rand(200,1),rand(200,1),'or')
scatter(rand(200,1),rand(200,1),'ok')
scatter(rand(200,1),rand(200,1),'+r')
figure(gcf); pause(2)
set(findobj(gcf,'Type','Patch','Marker','o'),'MarkerEdgeColor','b')

Weitere Antworten (1)

Amit
Amit am 16 Jun. 2017
Can you also interpolate the colors in between those stated values? I am struggling with this issue at the moment.

Kategorien

Mehr zu Orange finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by