I have a 3d scatterplot that needs updating. however, there is no variable that lets me address single datapoints.
self.fig = plt.figure(figsize=(8, 8))
self.ax = self.fig.add_subplot(111, projection='3d')
data_point = self.ax.scatter(xs=0, ys=0, zs=0)
I want to change the x,y,z coordinates but have only managed to change the z coordinate by using set_3d_properties(1,[0])
.
Other attributes like colour can easily be changed.
The program is supposed to be a dynamic simulation.
I tried searching for setter functions that let me address these coordinates set_offsets, set_data
. However, the only promising one (an attribute) _offsets3d
gave me a horribly long error message that ended with IndexError: invalid index to scalar variable.
code to reproduce:
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111, projection='3d')
size = 6
ax.set_xlim(-(size / 2), size / 2)
ax.set_ylim(-(size / 2), size / 2)
ax.set_zlim(-(size / 2), size / 2)
datapoint = ax.scatter(0,0,0)
datapoint.set_data([1,1]) # supposed to work, doesn't work
datapoint.set_3d_properties(0,[5]) # works, changes the z coordinate
plt.show()