Apply several properties to subplots without duplicated lines

94 ビュー (過去 30 日間)
Creatlee
Creatlee 2017 年 8 月 10 日
回答済み: Lukas 2020 年 4 月 10 日
Hi, I would like to make the below more succinct.
As
set(findobj(gcf,'type','axes'),'FontName','Calibri','FontSize',11,'FontWeight','Bold', 'LineWidth', 1,'layer','top');grid on
is written several times, I would like to know how to apply properties to all subplots all at once.
figure(1)
set(gcf,'position',[500 200 1000 600])
subplot(311)
stairs(A,B,'markersize',2,'marker','*','linewidth',1)
xlabel('Frequency (Hz)'),ylabel('Amplitude')
set(findobj(gcf,'type','axes'),'FontName','Calibri','FontSize',11, ...
'FontWeight','Bold', 'LineWidth', 1,'layer','top');grid on
subplot(312)
stairs(C,D,'markersize',2,'marker','*','linewidth',1)
xlabel('Frequency (Hz)'),ylabel('Amplitude')
set(findobj(gcf,'type','axes'),'FontName','Calibri','FontSize',11, ...
'FontWeight','Bold', 'LineWidth', 1,'layer','top');grid on
subplot(313)
plot(E,F,'MarkerSize',1,'LineWidth',1)
xlabel('Time [ms]'),ylabel('Amplitude')
set(findobj(gcf,'type','axes'),'FontName','Calibri','FontSize',11, ...
'FontWeight','Bold', 'LineWidth', 1,'layer','top');grid on
Thank you in advance!

採用された回答

Sangeetha Jayaprakash
Sangeetha Jayaprakash 2017 年 8 月 14 日
You can just call the line "set(findobj(gcf,'type','axes'),'FontName','Calibri','FontSize',11,'FontWeight','Bold', 'LineWidth', 1,'layer','top');grid on" after all the subplots have been plotted as follows:
figure(1)
set(gcf,'position',[500 200 1000 600])
subplot(311)
stairs(A,B,'markersize',2,'marker','*','linewidth',1)
xlabel('Frequency (Hz)'),ylabel('Amplitude')
subplot(312)
stairs(C,D,'markersize',2,'marker','*','linewidth',1)
xlabel('Frequency (Hz)'),ylabel('Amplitude')
subplot(313)
plot(E,F,'MarkerSize',1,'LineWidth',1)
xlabel('Time [ms]'),ylabel('Amplitude')
set(findobj(gcf,'type','axes'),'FontName','Calibri','FontSize',11, ...
'FontWeight','Bold', 'LineWidth', 1,'layer','top');grid on
Here, "findobj(gcf,'type','axes')" will find all the axes which correspond to the current figure handle.
  1 件のコメント
Creatlee
Creatlee 2017 年 8 月 15 日
Dear Sangeetha,
Thank you for your answer. This is what I was looking for!! Even I may use several other properties of figure based on your answer. Thank you! Have a nice day!

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

その他の回答 (1 件)

Lukas
Lukas 2020 年 4 月 10 日
For example: to switch the grid on on all the axes in a current figure (gcf)
arrayfun(@(x) grid(x,'on'), findobj(gcf,'Type','axes'))
The functio @(x) grid(x,'on') can be replaced with something more complex.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by