Dynamic Visualization of a Variable

In my 9 Axis IMU Lessons the following code is used to demonstrate a moving graphic. I can see where the lectures are going where we move ‘objects’ by the value read from the serial port. My issue the code in the lectures isn’t working for me.
This code below is from part of the lectures:

from vpython import *
import time

y=cylinder(length=6,radius=0.5,color=color.yellow)
y.pos=vector(-3,0,0)
j=0
change=0.5
while True:
    rate(20)
    j=j+change
    y.length=j
    if(j==10):
        change=-0.2
        if(j==1):
            change=0.2

I’ve created a cylinder successfully using this code

from vpython import *
import time

myCylinder = cylinder(pos=vector(-3,0,0), axis=vector(0,0,0),size=vector(6,0.5,0.5))

So, my thought process was this, to get it working dynamically:
replace size=vector(6,0.5,0.5) with size=vector(j,0.5,0.5) but the code throws up something unexpected when I run vpython

from vpython import *
import time

j=0
#y.pos=vector(-3,0,0)

change=0.5
while True:
    rate(20)
    myCylinder = cylinder(pos=vector(-3,0,0), axis=vector(0,0,0),size=vector(j,0.5,0.5))
    j=j+change
    #y.length=j
    if(j==10):
        change=-0.2
        if(j==1):
            change=0.2

Any help greatly appreciated for a newbie.

“throws up something unexpected”?

What did you expect and what did you get?

I want or expected the length of the cylinder to vary according to the j variable in the while True loop.

I’ve just been reading the VPython_Intro pdf and I believe what I’m seeing is the following:-

VPython by default tries to keep all of the objects visible, so as the ball moves far away from the origin, VPython moves the
“camera” back, and the wall recedes into the distance. This is called “autoscaling”.

So in my case the whole of the cylinder receedes backwards from the camera, when all I want it to do is increase then decrease along its length by the value of the variable j.

I’ve revised my code as below which gets me on the right path so to speak.

from vpython import *
import time

j=0

myCylinder = cylinder(pos=vector(-3,0,0), axis=vector(0,0,0),size=vector(j,0.5,0.5))
#y.pos=vector(-3,0,0)
myCylinder.pos=vector(-3,0,0)
change=0.5

while True:
    rate(20)
    j=j+change
    #y.length=j
    myCylinder.size=vector(j,0.5,0.5)
    if(j==10):
        change=-0.1
        if(j==1):
            change=0.1