Existing Subplot Figure Adjustment
10 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Adam Danz
on 31 Aug 2019
Edited: Adam Danz
on 1 Sep 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Subplots 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!