How do I change the axis exponent of several subplots at once?

6 ビュー (過去 30 日間)
Sander Janssen
Sander Janssen 2022 年 5 月 30 日
コメント済み: Sander Janssen 2022 年 5 月 30 日
Hello,
I was wondering if there is a way to change the exponent value of several subplots (all subplots within a figure) at once.
Currently I'm using:
ax = gca;
ax.YAxis.Exponent = 3;
This has to be done to each subplot seperately.
I have tried using:
arrayfun(@(x) YAxis.Exponent(x,3), findobj(gcf,'Type','axes'))
and:
arrayfun(@(x) Exponent(x,3), findobj(gcf,'Type','axes'))
Neither work since Matlab doesn't recognize the functions. Error:
Unrecognized function or variable 'exponent'.
Error in @(x)exponent(x,0)
I think something similar to what I've tried is possible, but I don't know what to put instead of "YAxis.Exponent".
Thank you.

採用された回答

Jan
Jan 2022 年 5 月 30 日
編集済み: Jan 2022 年 5 月 30 日
arrayfun(@(axH) set(axH.YAxis, 'Exponent', 3), findobj(gcf,'Type','axes'))
Alternatively:
AxesH = findobj(gcf,'Type','axes');
set([axesH.YAxis], 'Exponent', 6);
Remember that gca and gcf is fragile: As soon as the user clicks on a different figure, unexpected handles are replied. Prefer to store the handles of the axes objects explicitly, e.g.:
AxesH = gobjects(1, 6);
for k = 1:6
AxesH(k) = subplot(2, 3, k);
...
end
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 30 日
Nice use of structure expansion.
Sander Janssen
Sander Janssen 2022 年 5 月 30 日
Thank you, exactly what I was looking for.
I am aware that gca and gcf are fragile, thanks for the heads up though.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 30 日
subplot(2,1,1); plot(randn(1,20) * 1e5)
subplot(2,1,2); plot(randn(1,20) * 1e5)
yax = get(findobj(gcf,'Type','axes'), 'YAxis');
set([yax{:}], 'Exponent', 3)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by