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)
Show older comments
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
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
Is there a way to create a sequence of polar plots in a tiled layout using arrayfun with an anonymous function?
0 Comments
Answers (1)
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
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?
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


