0

I'm having a little bit of trouble ploting data of the size of two arrays or lists Arr_Particles and Arr_Particles2. I currently draw the figure to plot on when i intitiate my program then plot on it later using a function which is called every so often using a loop. The problem im having is that i have an animation of particles moving and colliding oin a pygame window and in order to plot points on the figure i have to pause the plotting which halts the animation of particles as it runs in a loop with graph() . I'm wondering if there is any way around this ?

code below:

code for creating arrays and figures:

Arr = []
Arr2 = []

fig = plt.figure()
ax = fig.add_subplot(111)
Ln, = ax.plot(Arr)
Ln1, = ax.plot(Arr2)
ax.set_xlim([0,100])
ax.set_ylim([0,40])
plt.ion()
plt.show()

The code called to plot is:

def Graph(Arr, Arr2, Arr_Particles, Arr_Particles2):


 #sets the variable Particle1No = the length of Arr_Particles
    Particle1No = len(Arr_Particles)
    #sets the variable Particle2No = the length of Arr_Particles2
    Particle2No = len(Arr_Particles2)

    #this appends the data from Particle1No to Arr
    Arr.append(Particle1No)
    #this sets ln y data as the data from Arr
    Ln.set_ydata(Arr)
    #this sets ln x data as len of Arr
    Ln.set_xdata(range(len(Arr)))

    #this appends the data from Particle2No to Arr2
    Arr2.append(Particle2No)
    #this sets ln y data as the data from Arr2
    Ln1.set_ydata(Arr2)
    #this sets ln x data as len of Arr2
    Ln1.set_xdata(range(len(Arr2)))

    #pauses plotting ( seems can be 0 or very close) ? it doesnt plot if this is removed either.
    plt.pause(0.1)

Any help would be Very much appreciated.

0 Answers0