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

5 次查看(过去 30 天)
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.

请先登录,再进行评论。

采纳的回答

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