Reputation: 143
I'm trying to plot 3D poses of hand using matplotlib. For every frame of video or we can say if data is changed then plot size(X, Y, Z) also changed with respect to object(hand poses) size and position. For more detail below are two screenshots with next and previous frame, in screenshots we can see that x, y and z axis are changed as hand pose is changed.
My question is that how to get a stable plot that it's size will not change even object position will be changed.
As a reference below is another image that shows a stable plot and I'm trying to get like this. As we can see that input frames and object size is changing but plot is with same size. No matter if object size will be changed in plot.
Below is my plotting code. Kindly take it just as plotting sample, I'm sharing only plotting code because problem is in plotting code.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(elev=20, azim=75)
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
rgb_dict = get_keypoint_rgb(skeleton)
for i in range(len(skeleton)): # here is skeleton, just ignore it
joint_name = skeleton[i]['name']
pid = skeleton[i]['parent_id']
parent_joint_name = skeleton[pid]['name']
x = np.array([kps_3d[i, 0], kps_3d[pid, 0]]) # kps_3d is pose data
y = np.array([kps_3d[i, 1], kps_3d[pid, 1]])
z = np.array([kps_3d[i, 2], kps_3d[pid, 2]])
ax.plot(x, z, -y, c = np.array(rgb_dict[parent_joint_name])/255., linewidth = line_width)
ax.scatter(kps_3d[i, 0], kps_3d[i, 2], -kps_3d[i, 1], c = np.array(rgb_dict[joint_name]).reshape(1, 3)/255., marker='o')
ax.scatter(kps_3d[pid, 0], kps_3d[pid, 2], -kps_3d[pid, 1], c = np.array(rgb_dict[parent_joint_name]).reshape(1, 3)/255., marker='o')
As ax.scatter
docs show that it is used to get a scatter plot of y vs. x with varying marker size and/or color.
Which alternative function I can use to get stable plots?
Looking for some valuable suggestions.
Upvotes: 0
Views: 613
Reputation: 18772
Try set the plot limits by these lines of code:
ax.set_xlim3d(-0.1, 0.1)
ax.set_ylim3d(-0.1, 0.1)
ax.set_zlim3d(-0.1, 0.1)
Adjust the numbers as needed. You may also need to adjust viewing angle:
ax.view_init(elev=28., azim=55)
Upvotes: 1