Is There a Way to Create a Sequence of Polar Plots in a Tiled Layout Using arrayfun with an Anonymous Function?
45 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Steven Lord
2025 年 11 月 24 日 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 件のコメント
Steven Lord
2025 年 11 月 24 日 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?
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



