how to add contourf(X, Y, Z) in the polaraxes

조회 수: 5 (최근 30일)
lang
lang 2025년 3월 21일
댓글: dpb 2025년 3월 22일
Hi, I've tried to overlay a polaraxes on top of the axes, but it's easy to deform in the subplot or tiledlayout and it looks more incongruous, is there a better way to fix it, or implement some other way to implement contourf in polaraxes. Here is my code. Just like shown, the polaraxes will move as other things get added, dealing with this situation can be pretty boring. And pax.RLim doesn't work as expected.
load("S.mat","S");
figure;
t=tiledlayout(1,2);
nexttile(t);
ax=nexttile(t);
paxctf(ax,S.f,S.th,S.efth);
colorbar(ax);
function [CS,CH,pax]=paxctf(ax,f,th,Efth)
assert(isvector(f) & isvector(th),'Error: f or th is not a vector!');
[ddir,df]=meshgrid(deg2rad(th),f);
[X,Y]=pol2cart(ddir,df);
[CS,CH]=contourf(Y,X,Efth,'LineStyle','none');
axis equal;
axis off;
POS=tightPosition(ax);
pax=polaraxes(gcf,'Position',POS);
pax.Color='none';
pax.ThetaZeroLocation="top";
pax.ThetaDir="clockwise";
pax.RAxisLocation=30;
pax.RTick=[0 1/20 1/10 1/6 1/4];
pax.RTickLabel={'','20 s','10 s','6 s','4 s'};
end
  댓글 수: 2
dpb
dpb 2025년 3월 21일
You forgot to attach some data so somebody here can try to duplicate your efforts...and it would undoubtedly be a big help if you could show an example of what it is you're trying to create from a published paper of a hand drawn sketch or ... Otherwise, it's a guess as to what the final objective really is.
lang
lang 2025년 3월 22일
Ok, I have updated the code.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2025년 3월 22일
I see what you mean - the colorbar added to the contourf axes has shifted the plot so that it no longer overlaps correctly the polar axes.
I did some quick googling and came across this answer, which proposed adding an event listener to one of the axes. You can read more about events here.
Doesn't hurt to try it out. Here is the result.
load("S.mat","S");
figure;
t=tiledlayout(1,2);
nexttile(t);
ax=nexttile(t);
paxctf(ax,S.f,S.th,S.efth);
colorbar(ax);
function [CS,CH,pax]=paxctf(ax,f,th,Efth)
assert(isvector(f) & isvector(th),'Error: f or th is not a vector!');
[ddir,df]=meshgrid(deg2rad(th),f);
[X,Y]=pol2cart(ddir,df);
[CS,CH]=contourf(Y,X,Efth,'LineStyle','none');
axis equal;
axis off;
pax=polaraxes(gcf);
pax.Color='none';
pax.ThetaZeroLocation="top";
pax.ThetaDir="clockwise";
pax.RAxisLocation=30;
pax.RTick=[0 1/20 1/10 1/6 1/4];
pax.RTickLabel={'','20 s','10 s','6 s','4 s'};
addlistener(ax,'MarkedClean',@(varargin)set(pax,'Position',get(ax,'Position')));
end
  댓글 수: 4
Cris LaPierre
Cris LaPierre 2025년 3월 22일
The polar and contour plots are on different axes, so yes, you'd have to adjust it manually.
dpb
dpb 2025년 3월 22일
Could not a callback on one fixup the other, @Cris? Each would need to futz with the other and it might get messy....
There isn't a generalized linkaxes that could specify comparative parameters between two dissimilar axes...and not likely to make the list of approved enhancement requests I'd wager? :)

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by