I have written some code in Spyder to run an animation of a probe orbiting the moon. When I run the code in Spyder it executes almost instantaneously. But when I run the code in a Jupyter notebook it takes almost 2 minutes. Why is this the case? Is there anything that I can do to make it execute as fast as Spyder? I will put the code down below and any suggestions or changes to optimise it are very welcome.
N=int(day/100)
x_pos, y_pos = task1(N, day)
fig = plt.figure() #creating a figure
ax = plt.axes() #creating an axis
ax = plt.axes(xlim=(-2*10**6, 2*10**6), ylim=(-2*10**6, 2*10**6)) #setting the scale of the axes
ax.set_aspect('equal', adjustable='box')
plt.title("Moon and probe",fontsize="x-large") #configuring title
plt.xlabel("Relative distance on scale of 1e7 meters",fontsize="small")
plt.ylabel("Relative distance on scale of 1e7 meters",fontsize="small")
patches = [] #list to store the bodies' identities
patches.append(plt.Circle((x_pos[0],y_pos[0]),5*10**4,color="pink", animated=True)) #configuring the identities of the patches representing the bodies
patches.append(plt.Circle((0,0),1.738*10**6,color="lightsteelblue", animated=True))
def init(): #creating method to add the representations of the bodies to the figure and the animation function
for i in range(0, len(patches)):
ax.add_patch(patches[i])
return patches
def animate(i): #creating a method animate the celestial bodies using the generated evolution of the system
patches[0].center = (x_pos[i],y_pos[i]) #setting the update rules for the motion picture
patches[1].center = (0,0)
return patches
numframes = len(x_pos)
anim = animation.FuncAnimation(fig, animate, init_func=init, frames = numframes, interval=100,blit=True)
#plt.show()
HTML(anim.to_jshtml())