I am trying to link the axes’ view of 3D subplots of an interactive plot with matplotlib. The code open two 3D scatter plots with random numbers. The right subplot should share the x- and y-axis with the one on the left. A property to share the z-axis seems to don't even exist...
from matplotlib import pyplot as plt
import numpy as np
fig = plt.figure()
axs = []
for i in range(2):
if i == 0:
ax = fig.add_subplot(1, 2, i + 1, projection='3d')
else:
ax = fig.add_subplot(1, 2, i + 1, projection='3d', sharex=axs[0], sharey=axs[0])
axs.append(ax)
# create data
x = np.random.rand(100, 1)
y = np.random.rand(100, 1)
z = np.random.rand(100, 1)
# plot (add points to axis)
ax.scatter(x, y, z)
# draw
plt.show()
I used interactive plotting with PyQt5 (simply call %matplotlib qt
to open interactive figures in a separate window)
Now, when I rotate a plot, only this one updates the view, but the second plot stays unaffected. However, I was expecting to see both plots being updated in sync because they share axes. I was expecting a similar behavior as MATLAB’s linkaxes
-function.