Home > Back-end >  update plot in while loop
update plot in while loop

Time:06-02

i got this code:

 while cap.isOpened():

    pose = results.pose_landmarks.landmark
    pose_row_x = list(np.array([[landmark.x] for landmark in pose]).flatten())
    pose_row_y = list(np.array([[landmark.y] for landmark in pose]).flatten())
    pose_row_z = list(np.array([[landmark.z] for landmark in pose]).flatten())

    df = pd.DataFrame(data=[pose_row_x, pose_row_y, pose_row_z ]).T
    df.columns = ["x", "y", "z"]
  


    plt.scatter(df['x'],df['y'])
    plt.plot()

I would like to print the new added values in "real Time" in the same plot. For every loop i got a new plot.

Is there any way to update the plot in every loop iteration ?

EDIT: PLOT: enter image description here I would be grateful for any help!

CodePudding user response:

I would recommend using a single Axes object for all of your plots. Something like this:

fig, ax = plt.subplots()

while cap.isOpened():

    # generate data here

    ax.scatter(df['x'], df['y'])
  • Related