Is There a Way to Create a Sequence of Polar Plots in a Tiled Layout Using arrayfun with an Anonymous Function?

44 views (last 30 days)
Sample data
s.th = pi/4:pi/4:2*pi;
s.r = [19 6 12 18 16 11 15 15];
s(2) = s(1); s(2).th = s(2).th*1.3;
If I want to make two plots in a tiled layout with Axes I can do this
figure
t = tiledlayout(1,2);
arrayfun(@(s) scatter(nexttile,s.th,s.r),s)
However, if I want to make polar scatter plots
figure
t = tiledlayout(1,2);
try
arrayfun(@(s) polarscatter(nexttile,s.th,s.r),s)
catch ME
ME.message
end
ans = 'Parent input must be a polaraxes object.'
Right. nextile does not return a PolarAxes object.
But there doesn't seem to be a way to force nexttile to create a PolarAxes nor can I find a function like a hypothetical nextpolar to use as the first argument to polarscatter.
Instead, as best I can tell a loop is required
figure
t = tiledlayout(1,2);
for ii = 1:2
h1 = nexttile;
polarscatter(s(ii).th,s(ii).r)
end
What's interesting here is that nexttile creates an Axes and then deep in the bowels of polarscatter a PolarAxes is created based on some properties of that Axes, and then Axes is deleted
h1
h1 =
handle to deleted Axes
Is there a way to create a sequence of polar plots in a tiled layout using arrayfun with an anonymous function?

Answers (1)

Steven Lord
Steven Lord on 24 Nov 2025 at 19:05
Using just an anonymous function alone? No, I don't think so. Probably the easiest way to do what you want is to define one general helper function and use a function handle to it in your arrayfun call.
s.th = pi/4:pi/4:2*pi;
s.r = [19 6 12 18 16 11 15 15];
s(2) = s(1);
s(2).th = s(2).th*1.3;
figure
t = tiledlayout(1,2);
arrayfun(@createPolarScatterPlot, s)
function createPolarScatterPlot(s)
nexttile
polarscatter(s.th, s.r)
end
  3 Comments
Steven Lord
Steven Lord on 24 Nov 2025 at 21:25
You can submit it as an enhancement request, but I'm not so sure nexttile should need to know about all the different types of axes that exist.
Right now, the axes documentation page lists Axes, PolarAxes, GeographicAxes, and "A standalone visualization, which is a chart designed for a special purpose that works independently from other charts." but I don't know whether there will be other types of axes in the future. Suppose we introduced SphericalAxes and/or CylindricalAxes as generalizations of PolarAxes -- would you expect nexttile to be able to create those types of axes immediately?
Paul
Paul on 24 Nov 2025 at 22:38
Edited: Paul on 25 Nov 2025 at 18:23
"would you expect nexttile to be able to create those types of axes immediately?"
I would expect nexttile to be able to create any type of axes that are compatible with a tiled layout. Clearly PolarAxes and GeographicAxes are compatible with a tiled layout. Why do (Cartesian) Axes get to be the only axes to play in the nexttile sandbox?
Maybe I'm missing something, but doesn't even seem like this would be that difficult. Conceptually, the easiest option would seem to have nexttile create an Axes and then go through the process to create the PolarAxes (or the GeographicAxes, etc.) from that Axes and then delete the Axes (*exactly* as done today deep down in polarscatter). nexttile would return the handle to whatever axes it creates.
Note: I'm assuming that geoplot (for example) works the same way as polarscatter wrt to creating the GeographicAxes when called following a call to nexttile.
Another minor annoyance with the current, two-step approach is that an extra call is needed to get the handle to the polaraxes
nexttile
polarscatter(args)
hpax = gca;
As opposed to something like
hpax = nextile(axes=polar);
polarscatter(hpax,args);
Just out of curiosity, any idea why nexttile wasn't called nextaxes?

Sign in to comment.

Products


Release

R2025b

Community Treasure Hunt

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

Start Hunting!