Existing Subplot Figure Adjustment
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Imran Joseph
el 31 de Ag. de 2019
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 comentarios
Respuesta aceptada
Adam Danz
el 31 de Ag. de 2019
Editada: Adam Danz
el 1 de Sept. de 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 comentarios
Adam Danz
el 31 de Ag. de 2019
Editada: Adam Danz
el 31 de Ag. de 2019
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!