I have a 2D plot placed on one of the walls of a 3D plot that doesn't seem to reflect any changes from set_data()
, I would like to understand what I'm doing wrong here.
Here is a sample code showing the 3D plot with the 2D 'projection' plot in question. The output is shown here:
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
# Test data for projection onto xz plane
t = linspace(0,10, num=20)
z = np.sin(t)
# Plot projection
projx, = ax.plot(np.linspace(-1,0, num=len(z)), z, 'r', zdir='y', zs=1)
# Labels and scaling
ax.set_xlabel('M_x')
ax.set_ylabel('M_y')
ax.set_zlabel('M_z')
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
# Update projection data
projx.set_data([0],[0])
# See if actually updated data
print(projx.get_xdata())
# Draw and display window
plt.draw()
ax.legend()
plt.show()
I imagine that this line:
projx.set_data([0],[0])
would make the projection plot virtually empty. Instead, the sine wave remains.
Furthermore, the printout yields [0]
as expected, so the set_data()
call was successful, but for some reason the plot doesn't get drawn with the new data.
Shouldn't the set_data() changes be reflected when drawn afterwards?