I want to generate a figure with 4 animations in python. I tried using the form below, but when running the program it generates the error ValueError: not enough values to unpack (expected 4, got 2)
. What could be wrong?
fig, (axF, axS, axH, axHamilt) = plt.subplots(2, 2)
graphF,=axF.plot([],[])
graphS,=axS.plot([],[])
graphH,=axH.plot([],[])
graphHamilt,=axHamilt.plot([],[])
axF.set_ylim(-1.5, 1.5)
axF.set_xlim(ri, rf)
axF.grid()
axS.set_ylim(-1.5, 1.5)
axS.set_xlim(ri, rf)
axS.grid()
axH.set_ylim(-1.5, 1.5)
axH.set_xlim(ri, rf)
axH.grid()
axHamilt.set_ylim(-1.5, 1.5)
axHamilt.set_xlim(ri, rf)
axHamilt.grid()
def animate(i):
graphF.set_data(r,Sevol[i])
graphS.set_data(r, Fevol[i])
graphH.set_data(r, Hevol[i])
graphHamilt.set_data(r, Hevol[i])
return graphF, graphS, graphH, graphHamilt
ani = FuncAnimation(fig, animate, frames=N_plots, interval=100)
plt.show()
CodePudding user response:
Note the parentheses:
fig, ((axF, axS), (axH, axHamilt)) = plt.subplots(2, 2)