Existing Subplot Figure Adjustment

조회 수: 8 (최근 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 CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by