필터 지우기
필터 지우기

Can this plot be recreated in matlab?

조회 수: 1 (최근 30일)
Ajmal Rasheeda Satheesh
Ajmal Rasheeda Satheesh 2023년 5월 3일
편집: DGM 2023년 5월 4일
Can such a figure be recreated in matlab?, a pcolor plot for 2 different color matrices (both matrices being different 2d arrays) with a 2d colorbar?
Any help will be appreciated
  댓글 수: 1
Les Beckham
Les Beckham 2023년 5월 4일
You will get better responses to your question if you provide sample data. Also, be specific about how you envision combining the "2 different color matrices". Are they to be stacked vertically, or what?

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

답변 (1개)

DGM
DGM 2023년 5월 4일
편집: DGM 2023년 5월 4일
There are no built-in plotting tools that perform 2D colormapping. You'll have to do it yourself. See this thread.
That uses a predefined image as a map. If we want to recreate the given example with four linearly-blended colors, we could do that or we could choose a more direct approach. Consider the simple example:
% some fake data
% both arrays must have the same geometry
z = peaks(100);
datax = z/3;
datay = rot90(z)/3;
% display the data using 1D maps
subplot(1,2,1)
imagesc(datax);
set(gca,'ydir','normal')
colormap(gray)
caxis([-1 1].*max(caxis)) % force mapping to be zero-centered
colorbar('southoutside')
title('xdata')
subplot(1,2,2)
imagesc(datay);
set(gca,'ydir','normal')
colormap(gray)
caxis([-1 1].*max(caxis)) % force mapping to be zero-centered
colorbar('southoutside')
title('ydata')
Now that we have an idea of what the x,y data looks like, it's time to create the colormap and create the output image representing the data.
% generate a 2D colormap patch for use as a "colorbar" of sorts
% this does linear interpolation in sRGB, so expect it to be muddy
% both CT0 and CTpatch will be upside-down for correct mapping and presentation
mapw = 256; % width/height of map
CT0 = [1 1 0; 0 0 1; 1 0 0; 0 1 0]; % corner colors [NW; SW; NE; SE]
CT0 = flipud(reshape(ctflop(CT0),2,2,3)); % now map is a 2x2 RGB image
xq = linspace(1,2,mapw);
yq = xq.';
CTpatch = zeros(mapw,mapw,3);
for c = 1:3
CTpatch(:,:,c) = interp2(CT0(:,:,c),xq,yq,'bilinear');
end
% interpolate data to make pseudocolor image
% specify color axes extents for colormapping
climx = [-1 1];
climy = [-1 1];
% clamp data to map extrema
xq = imclamp(datax,climx);
yq = imclamp(datay,climy);
% interpolate
dataimage = zeros([size(datax) 3]);
for c = 1:3
dataimage(:,:,c) = interp2(climx,climy,CT0(:,:,c),xq,yq,'bilinear');
end
% plot the data
figure
subplot(1,2,1)
image(dataimage)
set(gca,'ydir','normal')
grid on
title('this is my data')
xlabel('longitude')
ylabel('latitude')
% plot a "colorbar"
subplot(1,2,2)
image(climx,climy,CTpatch)
set(gca,'ydir','normal')
grid on
xlabel('size')
ylabel('shape')
You may choose to resize or reposition the axes used for the "colorbar" patch, or to otherwise present it differently.
The only major difference between this example and the one I linked to is that the other example used the data to do interpolation in the full 2D colormap (i.e. CTpatch in this example), whereas in this example the data is used to do interpolation on the base 2x2 map (CT0) which was used to generate CTpatch. This simplifies some things since we had to do the same thing to generate CTpatch anyway, but the interpolation could have otherwise been done using CTpatch instead. The reference vectors (the first two arguments to interp2()) would just have to be generated from climx,climy as appropriate.

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by