MATLAB: Parent patch to figure, not axes

parentpatch

I'm making a simple drawing in matlab, where certain coordinates are determined by the output of another code.
I've been doing this in a figure window, and it works fine for rectangles and lines (which have the figure window as parent) but whenever I create a patch, it also creates a set of axes, which I don't want. I want all the positions to relative to the figure window.
The code is below
% Create figure
figure1 = figure;
set(figure1,'units','normalized', 'Position', [0.1 0.1 0.6 0.8]);
annotation(figure1,'rectangle',...
[0.05 0.05 0.2 0.6],...
'FaceColor',[1 1 1],...
'LineStyle','none');
% Create rectangle


annotation(figure1,'rectangle',...
[0.05 la(i) 0.3 ma(i)],...
'FaceColor',[1 1-ca(i) 1-ca(i)],...
'LineStyle','none');
if i>1
if ma(i)>2e-16
X = [0.05; 0.15; 0.18; 0.02];
Y = [0.65; 0.65; 0.90; 0.90];
patch(X,Y,[1 1-ca(i) 1-ca(i)],'LineStyle','none');
end
end
annotation(figure1,'rectangle',...
[0.25 0.05 0.4 0.2],...
'FaceColor',[1 1 1],...
'LineStyle','none');
annotation(figure1,'rectangle',...
[0.35 0.25 0.3 0.2],...
'FaceColor',[1 1 1],...
'LineStyle','none');
if i>1
if m1(i)>2e-16 && la(i)>0.25
X1 = 0.30 + ((la(i)-0.2))*0.12;
X2 = 0.25 - ((la(i)-0.2))*0.12;
X = [0.25; 0.30; X1; X2];
Y = [0.25; 0.25; la(i); la(i)];
patch(X,Y,[1 1-c1(i) 1-c1(i)],'LineStyle','none')
end
end
% Create rectangle
annotation(figure1,'rectangle',...
[0.25 l1(i) 0.4 m1(i)],...
'FaceColor',[1 1-c1(i) 1-c1(i)],...
'LineStyle','none');
if i>1
if m2(i)>2e-16 && la(i) > 0.65
X1 = 0.40 + ((la(i)-0.4))*0.12;
X2 = 0.35 - ((la(i)-0.4))*0.12;
X = [0.35; 0.40; X1; X2];
Y = [0.45; 0.45; la(i); la(i)];
patch(X,Y,[1 1-c2(i) 1-c2(i)],'LineStyle','none')
end
end
% Create rectangle
annotation(figure1,'rectangle',...
[0.35 l2(i) 0.3 m2(i)],...
'FaceColor',[1 1-c2(i) 1-c2(i)],...
'LineStyle','none');
% Create line
annotation(figure1,'line',[0.05 0.05],[0.05 0.65],'LineWidth',3);
annotation(figure1,'line',[0.05 0.65],[0.05 0.05],'LineWidth',3);
annotation(figure1,'line',[0.25 0.25],[0.05 0.25],'LineWidth',3);
annotation(figure1,'line',[0.65 0.65],[0.15 0.25],'LineWidth',3);
annotation(figure1,'line',[0.30 0.65],[0.25 0.25],'LineWidth',3);
annotation(figure1,'line',[0.35 0.35],[0.25 0.45],'LineWidth',3);
annotation(figure1,'line',[0.40 0.65],[0.45 0.45],'LineWidth',3);
annotation(figure1,'line',[0.65 0.65],[0.35 0.45],'LineWidth',3);
annotation(figure1,'line',[0.15 0.45],[0.65 0.65],'LineWidth',3);
annotation(figure1,'line',[0.45 0.45],[0.45 0.65],'LineWidth',3);
The patches are in the if statements.
I had this working earlier, but for some reason it changed, and I can't work out why!
Thanks

Best Answer

If your goal is just not to see the axes, you could do this:
set(gca,'visible','off')
A patch object cannot be the child of a figure. Setting the axes to invisible will make it so that you only see the patches, not the axes.