Skip to content

Commit 4b470e5

Browse files
committed
Bug fix: legends and colorbars were not exported when exporting axes handle in HG2
1 parent 31c9e43 commit 4b470e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

isolate_axes.m

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
% 05/12/13: Bug fix to axes having different units. Thanks to Remington Reid for reporting
3030
% 21/04/15: Bug fix for exporting uipanels with legend/colorbar on HG1 (reported by Alvaro
3131
% on FEX page as a comment on 24-Apr-2014); standardized indentation & help section
32+
% 22/04/15: Bug fix: legends and colorbars were not exported when exporting axes handle in HG2
3233

3334
% Make sure we have an array of handles
3435
if ~all(ishandle(ah))
@@ -71,7 +72,9 @@
7172
set(ah(a), 'Tag', old_tag{a});
7273
end
7374
% Keep any legends and colorbars which overlap the subplots
74-
lh = findall(fh, 'Type', 'axes', '-and', {'Tag', 'legend', '-or', 'Tag', 'Colorbar'});
75+
% Note: in HG1 these are axes objects; in HG2 they are separate objects, therefore we
76+
% don't test for the type, only the tag (hopefully nobody but Matlab uses them!)
77+
lh = findall(fh, 'Tag', 'legend', '-or', 'Tag', 'Colorbar');
7578
nLeg = numel(lh);
7679
if nLeg > 0
7780
set([ah(:); lh(:)], 'Units', 'normalized');
@@ -84,7 +87,11 @@
8487
ax_pos = cell2mat(ax_pos(:));
8588
end
8689
ax_pos(:,3:4) = ax_pos(:,3:4) + ax_pos(:,1:2);
87-
leg_pos = get(lh, 'OuterPosition');
90+
try
91+
leg_pos = get(lh, 'OuterPosition');
92+
catch
93+
leg_pos = get(lh, 'Position'); % No OuterPosition in HG2, only in HG1
94+
end
8895
if nLeg > 1;
8996
leg_pos = cell2mat(leg_pos);
9097
end

0 commit comments

Comments
 (0)