필터 지우기
필터 지우기

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

조회 수: 15 (최근 30일)
Jessica
Jessica 2013년 2월 11일
답변: Amit 2017년 6월 16일
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?

채택된 답변

ChristianW
ChristianW 2013년 2월 11일
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')

추가 답변 (1개)

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

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by