Borrar filtros
Borrar filtros

Why is drawnow ignoring object ordering during animation?

3 visualizaciones (últimos 30 días)
Warren el 18 de Jul. de 2014
Editada: Warren el 19 de Jul. de 2014
I have lineseries X, lineseries Y, and text object T. I have set the data sources for X and Y to a variable that I update on every iteration of a for loop and use refreshdata(hx,'caller') and refreshdata(hy,'caller'). I also update the position of T to coincide with that of X on every iteration and finally call drawnow.
It is important that the text remain in front of X (its a label for X) and that if X and Y ever cross paths that Y appear behind X (Y is the shadow of X on the ground). But instead, sometimes X goes in front of Y and sometimes behind, and T spends most of its time behind X.
I have tried both uicontrol and reordering the children of the axes using get and set. At first I just set the ordering before the animation loop, but I also tried resetting the order right before drawnow using findobj(gca,'type',..) and set(gca,'children',....). Furthermore, whether or not I have those lines in or before the for loop, when I stop the program and examine the axes' children they are in the right order, even though they are not plotted in that order.
Also, lets say there are four points represented by X that are originally plotted by feeding 4 x-values, 4 y-values and 4-zvalues to plot3(..). (Since Y is the shadow, it is also created with plot using the same vector of x's and the same vector of y's, but z=[0 0 0 0]. And the position of T is the same as X) Then get(gca,'children') returns ['text';'line';'line']. So I thought this meant that the axes grouped all 4 X's as an object, all 4 Y's as an object, and all 4 T's as an object. But a freeze frame of the animation might show 3 of the T's behind their X's and 1 in front, and one X behind someone's shadow(Y) even though another X is in front of someone's Y. The documentation on uicontrol makes it sound as if axes objects are plotted in series, but it appears that this can't be true!
Does this have to do with animation? (I've tried pause(), too). I've set up simple non-animated examples and they draw in order and using get and set on children immediately changes the order without prompting to redraw.
I'm using Matlab 2014a on Ubuntu 14.04.
Thanks in advance for any advice!
Here are some parts of the original code. X corresponds to hp and Y corresponds to hpshadowxy.
hold on;
%%%OMITTED: set properties of axes
%%%%%%%%%%%Create Shadows
shadowcolor=colormap-[.05 .05 0;.05 .05 .05;.05 .05 0];
% Put the first lineseries (X) on top
%%%%%OMITTED: then create the text labels
%%%OMITTED: Get new data and do interpolation to
update xi, yi, zi
refreshdata(hp,'caller'); %And I've tried in the other order
%%%OMITTED: Update label positions manually in for loop
%%%Fixing orders here didn't help the text situation any
% htext=findobj(gca,'type','text');
% hlines=findobj(gca,'type','line');
% hpatches=findobj(gca,'type','patch');
% set(gca,'children',[htext;hlines;hpatches]);
% pause(.00001);

Respuestas (1)

Alfonso Nieto-Castanon
Alfonso Nieto-Castanon el 18 de Jul. de 2014
You may use plot3(x, y, z,...) and text(x, y, z,...) and control the relative front/behind positions of these elements with the extra z parameters (higher values will appear in front).
  1 comentario
Warren el 19 de Jul. de 2014
I'm not sure I understand. The plot is in 3-dimensions so I am already using the x,y,and z arguments to plot3. I don't think plot3 is using line-of-sight to order the plot because the shadows (Y above) always have smaller z components than any of the X's but are often plotted in front. I'll include some parts of the code above to make this clearer...

Iniciar sesión para comentar.


Más información sobre Graphics Performance 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!

Translated by