Flickering and drawnow plot

classic Classic list List threaded Threaded
5 messages Options
RT
Reply | Threaded
Open this post in threaded view
|

Flickering and drawnow plot

RT
I'm trying to animate two 3d plots at the same time but I keep getting flickering does anyone now of a workaround or how to prevent the flickering?

See code below:  I'm using octave 4.0 on ubuntu 16.04 64bit

k1 = 1; %how many times you want wave to oscillate in x-dir
k2 = 1; %how many times you want wave to oscillate in y-dir
u = linspace(-pi,pi,30); %how many segments
v = linspace(-pi,pi,30); % how many segments
[x,y] = meshgrid(u,v);  %how many segments

w_len=max(length(x))

for ii=1:180
  z=sin(k2*x+(ii)*pi/180);
  z2=-sin(k2*y+(ii)*pi/180);
 
  surf(x,y,z);
  drawnow
  surf(x,y,z2);
  drawnow
 
  pause(.001)

end

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Flickering and drawnow plot

Colin Macdonald-2
On 13/05/16 20:50, RT wrote:
> I'm trying to animate two 3d plots at the same time but I keep getting
> flickering does anyone now of a workaround or how to prevent the flickering?

You could try plotting the surfaces *once* outside the loop, keeping
their handles.  Then set their zdata property within the loop.

I haven't actually tested this recently.

Colin


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Flickering and drawnow plot

ratulloch
Can you point to an example?  I'm not exactly sure what you mean.

On Sat, May 14, 2016 at 2:14 AM, Colin Macdonald <[hidden email]> wrote:
On 13/05/16 20:50, RT wrote:
> I'm trying to animate two 3d plots at the same time but I keep getting
> flickering does anyone now of a workaround or how to prevent the flickering?

You could try plotting the surfaces *once* outside the loop, keeping
their handles.  Then set their zdata property within the loop.

I haven't actually tested this recently.

Colin


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Flickering and drawnow plot

Colin Macdonald-2
On 14/05/16 10:19, Rick T wrote:
> Can you point to an example?  I'm not exactly sure what you mean.

Something like:

z = ...
figure(1); clf;
h = surf(x,y,z)

for i=1:10
  z = ...
  set(h, 'zdata', z)
end


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Flickering and drawnow plot

Pantxo
In reply to this post by RT
RT wrote
I'm trying to animate two 3d plots at the same time but I keep getting
flickering does anyone now of a workaround or how to prevent the flickering?

See code below:  I'm using octave 4.0 on ubuntu 16.04 64bit

k1 = 1; %how many times you want wave to oscillate in x-dir
k2 = 1; %how many times you want wave to oscillate in y-dir
u = linspace(-pi,pi,30); %how many segments
v = linspace(-pi,pi,30); % how many segments
[x,y] = meshgrid(u,v);  %how many segments

w_len=max(length(x))

for ii=1:180
  z=sin(k2*x+(ii)*pi/180);
  z2=-sin(k2*y+(ii)*pi/180);

  surf(x,y,z);
  drawnow
  surf(x,y,z2);
  drawnow

  pause(.001)

end

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
You can also bind surface "zdata" to a given variable using "zdatasource" and then use "refreshdata ()" to update plots when the variable has changed. Something like:

  ...
  w_len=max(length(x))

  z = z2 = x;
  surf (x, y, z, "zdatasource", "z");
  hold on
  surf (x, y, z2, "zdatasource", "z2");
  for ii=1:180
    z=sin(k2*x+(ii)*pi/180);
    z2=-sin(k2*y+(ii)*pi/180);
    refreshdata ()

    pause(.001)

  end


Pantxo