필터 지우기
필터 지우기

Is it possible to overlay pcolor plots using hold on?

조회 수: 19 (최근 30일)
Ajmal Rasheeda Satheesh
Ajmal Rasheeda Satheesh 2022년 2월 9일
답변: Walter Roberson 2022년 2월 9일
I was trying to overlay pcolor plots using hold on but I get the following error "Error using colormap (line 61) First argument must be a scalar axes or figure handle".
Any idea on what might be going wrong? Thanks
f1 = figure(Visible="on");
Y=pcolor(T,H, A');
set(Y, 'EdgeColor', 'none');
set(gca,'ColorScale','log');
hold on
Z=pcolor(T,H, abs(B'));
set(Z, 'EdgeColor', 'none');
set(gca,'ColorScale','log');
cmp1 = colormap(jet);
cmp1 = [1 1 1;cmp1];
cmp2 = colormap("parula");
cmp2 = [1 1 1;cmp2];
colormap(Y,cmp1);
colormap(Z,cmp2);
hold off

채택된 답변

Walter Roberson
Walter Roberson 2022년 2월 9일
colormap(Y,cmp1);
If you pass in more than one positional parameter to colormap, then the first parameter must be an axes.
It is not possible to colormap() individual pcolor() objects.
You can however use rescale() (or the earlier mat2gray()) to convert the input values to the 0 to 1 range, multiply by the number of colors in the color map, floor(), uint8(), and then ind2rgb() against the colormap, in order to get an RGB equivalent. Or use the FIle Exchange contribution Freeze Colors.

추가 답변 (1개)

Highphi
Highphi 2022년 2월 9일
f1 = figure;% (Visible="on");
Y = pcolor(T, H, A');
set(Y, 'EdgeColor', 'none');
set(gca,'ColorScale','log');
hold on
cmp1 = colormap(jet);
cmp1 = [1 1 1;cmp1];
set(gca, 'Colormap', cmp1)
Z = pcolor(T, H, abs(B'));
set(Z, 'EdgeColor', 'none');
set(gca,'ColorScale','log');
cmp2 = colormap("parula");
cmp2 = [1 1 1;cmp2];
set(gca, 'Colormap', cmp2);
hold off
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 2월 9일
You are using the same axes both times there, but any one axes can only have one colormap.
See the File Exchange contribution FreezeColors()

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by