0
#3d dynamic scatterplot
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import time

plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
s=0
a=1
b=2
for i in range(0, 10):   
    s=a+b
    ax.set_xlabel('X axis')
    ax.set_ylabel('Y axis')
    ax.set_zlabel('Z axis')
    x = np.random.rand(5, 3) 
    y = np.random.rand(5, 3)
    z = np.random.rand(5, 3)
    #ax.cla()    
    ax.scatter(x[:, 0], y[:, 1], z[:, 2])
    plt.draw()
    time.sleep(1)   #make changes more apparent/easy to see
    a=a+1
    b=b+2
    if s>10:
         break;

このプロットは、反復ごとに一連の点を生成します。しかし、すべての反復の最後に、異なる世代のポイントを区別することはできません。では、各世代ポイントに異なる色を付けることは可能ですか? また、n回の反復が可能でなければなりません。

4

1 に答える 1