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

4 visualizzazioni (ultimi 30 giorni)
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 Commenti
dpb
dpb il 21 Mar 2025
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 il 22 Mar 2025
Ok, I have updated the code.

Accedi per commentare.

Risposta accettata

Cris LaPierre
Cris LaPierre il 22 Mar 2025
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 Commenti
Cris LaPierre
Cris LaPierre il 22 Mar 2025
The polar and contour plots are on different axes, so yes, you'd have to adjust it manually.
dpb
dpb il 22 Mar 2025
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? :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Axes Appearance in Help Center e File Exchange

Tag

Prodotti


Release

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by