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

6 ビュー (過去 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 Center および File ExchangeAxes Appearance についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by