Parent patch to figure, not axes

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

 채택된 답변

Matt Fig
Matt Fig 2011년 5월 24일

2 개 추천

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.

댓글 수: 7

Paul
Paul 2011년 5월 24일
Thanks, that solves half the problem. The positions of the patches are still set by the (invisible) axes though. I want the positions to be relative to the figure window, like the lines and rectangles are.
Matt Fig
Matt Fig 2011년 5월 24일
At the beginning of the code, create your invisible axes:
axes('visible','off','units','normal','pos',[0 0 1 1]);
See if that does what you expect. You then should normalize the inputs to the patch command.
Paul
Paul 2011년 5월 25일
Thanks, I think we're getting somewhere. I also had to set the x and y limits to [0 1], but now the patches are in the right place. Unfortunately, one of them is hidden behind a rectangle, and I can't find any way of bringing it forward. Any ideas?
Matt Fig
Matt Fig 2011년 5월 25일
Hello Paul,
You can control what object is on top by manipulating the stacking order. Here is a quick example:
axes;
P = patch([0;1;1],[1;2;1],[0;0;0],[1 .5 .3]);
R = rectangle('facecolor','b','pos',[.5 .5 .5 1]);
pause(1.5)
ch = get(gca,'children'); % this has the order
set(gca,'children',ch([2 1]))
Walter Roberson
Walter Roberson 2011년 5월 25일
Paul, you may need to change renderers to get the patch to move visually. The OpenGL renderer does not use the uistack() order for objects that are in the same plane: instead OpenGL defines in such cases the order in which lines and surfaces in the same plane will be drawn. This is an OpenGL property, and does not apply to the other renderers.
If you were using transparency then OpenGL would be your only choice, in which case you would have to use another tactic: namely, if you want the patch to be in front of the rectangle, then use an explicit Z coordinate for the patch that is "above" the implicit zero Z coordinate of 2D objects.
Paul
Paul 2011년 5월 26일
Thanks for the ideas. I actually managed to solve the problem by making all of the fixed elements of the image into a background image that I then attached to a set of axes behind the axes with the patches on it.
Just out of interest Matt, what is the purpose of the pause in your code above?
Matt Fig
Matt Fig 2011년 5월 26일
The pause was there so that you would see the change happen, otherwise it would be to fast!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2011년 5월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by