Why does mutating the input to matplotlib's Axes3D.plot() and .scatter() methods behave differently?

Viewed 522

In the code posted in the question How can I draw a multiple 3d-curves picture by Python?, plot method is called twice and since the points to plot are not resetting, the lines are drown on top of the other. But instead of plot() if we try with the scatter method, we can see points plotted in different location. Why does this change in the behavior?

The code is copied below

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import math as mt
from mpl_toolkits.mplot3d import Axes3D


t=2  #t can be changed

fig = plt.figure()
ax=Axes3D(fig)

#data

def unitilize(x,y,z):
    r=mt.sqrt(x**2+y**2+z**2)
    return x/r, y/r, z/r

def g_1(x,y,z):
    x=t*x                
    z=z/t                
    x,y,z=unitilize(x,y,z)
    return x,y,z

stepCnt=10000            ######step 
#########data#################
xs = np.empty((stepCnt + 1,))
ys = np.empty((stepCnt + 1,))
zs = np.empty((stepCnt + 1,))

#Setting initial values
def huatu(x,y,z):   

    xs[0], ys[0], zs[0] =unitilize(x,y,z)

    for i in range(stepCnt):
        xs[i+1],ys[i+1],zs[i+1]=g_1(xs[i], ys[i], zs[i])
    return xs,ys,zs


xs3,ys3,zs3=huatu(1,10,40)
ax.plot(xs3, ys3, zs3, color='b', marker='x')

xs2,ys2,zs2=huatu(1,0,40)
ax.plot(xs2, ys2, zs2, color='r', marker='o')
plt.show()

Plot output: enter image description here

Scatter output: enter image description here

1 Answers
Related