1

I have an array of arrays with format [2000][200,3] that I am creating an animated scatter plot of. 2000 is the number of frames and the interior arrays have format [length, [x,y,inten]] which are the points to scatter. So for an example a single frame will look like:

Array[0]=np.array([x_1,y_1,I_1],[x_2,y_2,I_2],...,[x_200,y_200,I_200])

So we have 2000 frames of 200 points each. These points are arbitrarily truncated every 200 and are actually sequential. So I can feasibly reshape the array into:

Array=np.array(np.array([x_1,y_1,I_1],[x_2,y_2,I_2],...,[x_400000,y_400000,I_400000])

Which is no problem for me. I know how to do this.

My question is how can I animate a scatter plot that adaptively moves through the points instead of displaying 200 point bins? The code below allows me to plot an animated scatter plot with frames (1-200,201-400,401-600,etc) but the result is not very smooth to the eye. Ideally I would like something that updates at every point or at least every 10 points so for example frames (1-200,2-201,3-202,etc) or (1-200,11-210,21-200,etc)

numframes=len(Array)

plt.ion()
fig, ax = plt.subplots()

norm = plt.Normalize(Array[:][:,2].min(), Array[:][:,2].max())
sc = ax.scatter(Array[0][:,0], Array[0][:,1], c=Array[0][:,2], cmap=cm.hot, s=5)

plt.xlim(-40,40)
plt.ylim(0,200)
plt.draw()
for i in range(numframes):

    sc.set_offsets(np.c_[Array[i][:,0], Array[i][:,1]])
    sc.set_array(Array[i][:,2])
    print(i)
    plt.pause(0.1)

plt.ioff()
plt.show()
  • I find it very difficult to understand what your problem is. Are you asking [how to slice your array](https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation) in bins smaller than 200? In any case, please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Usually, trying to come up with a simplified version of your problem will help you solve it on your own. – Diziet Asahi Dec 29 '17 at 12:43

1 Answers1

0

The code below steps continuously through my array of points with a given step size and window of 200 instead of discretely binning every 200.

stepsize=10
NewArray=np.ravel(Array)
NewArray.reshape(2000*200,3)

plt.ion()
fig, ax = plt.subplots()
norm = plt.normalize(NewArray[:,2].min(), NewArray[:,2].max())
sc = ax.scatter(NewArray[0:200,0], NewArray[0:200,1], c=NewArray[0:200,2], cmap=cm.jet, s=5)
plt.xlim(-40,40)
plt.ylim(0,200)
plt.draw()
for i in range(len(NewArray//stepsize)-200):
    sc.set_offsets(np.c_[NewArray[(i*stepsize):(i*stepsize)+200,0],\
                            NewArray[(i*stepsize):(i*stepsize)+200,1]])
    sc.set_array(NewArray[(i*stepsize):(i*stepsize)+200,2])

    plt.pause(0.1)

plt.ioff()
plt.show()