Existing Subplot Figure Adjustment

9 ビュー (過去 30 日間)
Imran Joseph
Imran Joseph 2019 年 8 月 31 日
編集済み: Adam Danz 2019 年 9 月 1 日
I'm in the process of creating roughly 100 figures,
After creation they look like the figure NT_0D as it is easier for me to include the contour values.
However, for saving the figures as Images, I want to be able to adjust the figure such that looks like N1_0D.
As it looks much better, but I dont know how to write the code to adjust existing figure plots that such that I can do so without individually adjusting each figure by hand.
Any help would be greatly appreaciated.

採用された回答

Adam Danz
Adam Danz 2019 年 8 月 31 日
編集済み: Adam Danz 2019 年 9 月 1 日
Create new axes to match a template
You could treat N1_0D.fig as a template by opening the figure, clearing all of the axes and filling them with new data.
% Name template figure (the ideal figure)
templateFig = 'N1_0D.fig';
% Open the template figure
templateHand = open(templateFig);
% Get all axis handles
axHand = findall(templateHand, 'Type', 'axes');
% Clear all axes
arrayfun(@cla,axHand)
% plot your new data; the axes order will always be the same
% "right" titled plot
contourf(axHand(1), . . .)
% "front" titled plot
contourf(axHand(2), . . .)
% "left" titled plot
contourf(axHand(3), . . .)
% "back" titled plot
contourf(axHand(4), . . .)
Alter existing axes to match a template
% Name template figure (the ideal figure)
templateFig = 'N1_0D.fig';
% Open the template figure
templateHand = open(templateFig);
% Get all axis handles
axHand = findall(templateHand, 'Type', 'axes');
% Get all colorbar handles
cbHand = findall(templateHand, 'Type', 'ColorBar');
% get axis positions
axPos = get(axHand,'Position');
% Get colorbar positions
cbPos = get(cbHand,'Position');
% Open the target figure
targetFig = 'NT_0D.fig';
targetHand = open(targetFig);
% Set the figure to match the template figure size (optional)
targetHand.Position = templateHand.Position;
% Get all axis handles
targAxHand = findall(targetHand, 'Type', 'axes');
% Get all colorpar handles
targcbHand = findall(targetHand, 'Type', 'ColorBar');
% Assuming the axes are in the same order*,
set(targAxHand, {'Position'}, axPos)
% Assuming the colorbars are in the same order*,
set(targcbHand, {'Position'}, cbPos)
% * If the axes are not in the same order you'll need to use the
% axis titles to match the correct axes. To get a list of axis
% titles: arrayfun(@(h)h.Title.String,axHand,'UniformOutput',false)
  2 件のコメント
Imran Joseph
Imran Joseph 2019 年 8 月 31 日
編集済み: Imran Joseph 2019 年 8 月 31 日
Thanks for getting back to me,
Damn, so the most likely solution is that I would have to redo all my data plotting, rather than being able to adjust NT_0D to the template.
Or would I be able to do something like
%% Name template figure (the ideal figure)
templateFig = 'N1_0D.fig';
% Name target fig
trgtFig = 'NT_0D.fig';
%% Open the template figure
templateHand = open(templateFig);
% Get all axis positions template
axHand = findall(templateHand, 'Type', 'axes', 'Positions', 'OuterPosition');
% Open target figure
trgtHand = open(trgtFig);
%Adjust Position on target file to match template
%some code
Adam Danz
Adam Danz 2019 年 8 月 31 日
編集済み: Adam Danz 2019 年 8 月 31 日
I updated my answer with a method of altering your existing figures to match the axes and colorbar positions of the template figure. You'll just need to list all figure names in a cell array and run them through the code in a loop.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by